anki-connect
anki-connect copied to clipboard
[Discussion] Support for running arbitrary hooks
I'm working on a few projects where it would be nice if there was a way to call an add-on function through anki-connect. This would allow me to invoke the custom card previewer I implemented in Internal References from an outside app, for instance. Currently there doesn't seem to be any way to do this aside from monkey-patching anki-connect's internals, which does not seem like a good option in the long-run.
That's why I was thinking about submitting a PR that would add an API call for running an arbitrary hook through anki-connect. Add-on authors would then be able to make their functions callable with addHook("hookname", function)
. To avoid interfering with Anki's own hooks and make the API call safer, perhaps it would also be best if we enforced the hook names to follow a specific naming scheme, e.g. "acHook...".
Would you be open to this idea, generally speaking? I'm more than happy to submit a PR, but I thought it would be better if I asked beforehand.
So basically what you want to do is get code in your own addon to be executed by AnkiConnect when specific messages arrive? That sounds fine to me, and is of course much better than messing around with AnkiConnect internals since that's just asking for your extension to break during the next cleanup/refactor/whatever pass.
It's funny, after so many years doing Anki extensions I haven't ever used the hook APIs in any of my code. Do you think it would be possible to somehow make things work with the versioning system inside AnkiConnect? I would see this as providing a version number when adding hooks or something.
Thanks for the quick reply. Awesome. I will try to submit a PR over the weekend then and see if I can work in support for the versioning system.