Replies: 2 comments 1 reply
-
A few things to consider, while thinking broadly about hooks:
I'm only presenting these for consideration -- maybe something sparks a broader, more comprehensive new Hooks design that would enable some cool new things. |
Beta Was this translation helpful? Give feedback.
-
Good questions, @djmitche. I'm not a big user of sync, so I haven't thought much about those. Will leave the community to comment. Some of these could be configured by the user if we are willing to give up on the simplicity of just dropping a file and make hooks configurable on the config file. Or we can have sane defaults for just drop ins. On your second point, I do not think filtering each individual field would be good for performance or for plugin developer UX. It'll be better to be able to filter the change set at the individual task level, imo. |
Beta Was this translation helpful? Give feedback.
-
While working on #3229 I thought about a potential improvement about how we implement Hooks.
There are fundamentally two classes of scripts that want to hook into Taskwarrior.
The first class I'm calling filters and they want to receive a value with the intention of modifying it and returning it to Task to persist it. For example, a script that hooks into on-add and based on some conditions adds a tag to the task. Due to the nature of these, we need to run them synchronously and wait for their response.
The second class I'm calling triggers and they want to receive one or multiple values but they don't need to return any change to Task. They want the data to run an "offline" operation like logging, doing a backup, sending a notification, etc. These scripts could be run in a "fire and forget" kind of way, spawning a separate thread, and not block Task execution waiting. This would allow us to be less conservative on how many of these triggers we add around the codebase, making Taskwarrior more extensible and flexible without compromising UX.
The new Hooks API would expose a few methods to trigger these hooks, passing a name, one of the most common values we may want to trigger for, and an arbitrary vector of string parameters to send to the script:
And another set of functions to filter the 4 most common types of data we may want to have filters for. These will also support passing an arbitrary vector of extra data to share with the script, if needed. The first parameter would be the filter name.
On the script registration side I see two main paths:
We keep the current system, using file names to tell Task where to hook to. In this case we can extend the nomenclature to define triggers vs filters.
We remove a little bit of magic and make users configure these hooks in the config file. This would mean a bit extra work from the user, but could allow a few interesting changes:
Beta Was this translation helpful? Give feedback.
All reactions