-
-
Notifications
You must be signed in to change notification settings - Fork 288
Description
β οΈ Please check that this feature request hasn't been suggested before.
- I searched previous Ideas in Discussions didn't find any similar feature requests.
- I searched previous Issues didn't find any similar feature requests.
π Feature description
I am a plugin developer and would like to allow users of my plugin who also use Tasks to be able to toggle events as completed from a custom view in my plugin. I've suggested one way to do this below with Obsidian events, but happy to discuss more about what the best way to do this is.
βοΈ Solution
Some core plugins provide actions that 3rd-party plugins can trigger in order to perform actions that are normally handled by the core plugin. For example, the Page preview
plugin exposes an event hover-link
that lets other plugins trigger hover previews over any element. It is triggered with a call like so:
// `jsEvent` is the JavaScript mouse event that shows where the mouse currently is.
this.app.workspace.trigger("hover-link", {
event: jsEvent,
source: "MY_PLUGIN_SLUG",
hoverParent: parentElement,
targetEl: jsEvent.target,
linktext: "path/to/file",
sourcePath: "path/to/file",
});
New actions can be created by listening with this.app.workspace.on()
.
Tasks could provide an action that plugins would be able to call with something like:
this.app.workspace.trigger("toggle-task", {
source: "MY_PLUGIN_SLUG"
path: "path/to/file",
lineNumber: <line number for Task>
});
There are other objects that implement the Events
interface (see here), in case you think there's one that's a better fit for registering this than app.workspace
.
There could also be another Event that gets triggered when the Cache gets updated, so that plugins listening to that Event can keep track of tasks without having to parse them themselves.
β Alternatives
An alternative way to allow other plugins to modify tasks is to factor out all of the Task parsing and printing code into a separate library published on NPM that can be included in the Tasks plugin as well as any other plugin that would like to modify tasks. This is the approach taken by [@]liamcain with obsidian-daily-notes-interface, which they use for Calendar to create and navigate between a user's daily notes.
Downsides of this alternative:
- A lot of work to pull the required functionality out of the plugin into a library.
- Third-party plugin authors who use the library will need to keep it up-to-date with the Tasks plugin. If a plugin that uses the library hasn't been updated in a while, modifications to Tasks code through that plugin will use the old code.
π Additional Context
I'm the developer of the Obsidian Full Calendar plugin which supports basic task lists, and am starting to investigate adding Tasks support to the plugin (obsidian-community/obsidian-full-calendar#219).