mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 02:22:26 +08:00
4.4 KiB
Vendored
4.4 KiB
Vendored
"New Task" launcher button
In this example we are going to extend the functionality of Task Manager showcase (which comes by default with Trilium) by adding a button in the Launch Bar () to create a new task automatically and open it.
Creating the note
- First, create a new Code note type with the JS frontend language.
- Define the
#run=frontendStartup
label in Attributes.
Content of the script
Copy-paste the following script:
api.addButtonToToolbar({
title: "New task",
icon: "task",
shortcut: "alt+n",
action: async () => {
const taskNoteId = await api.runOnBackend(() => {
const todoRootNote = api.getNoteWithLabel("taskTodoRoot");
const resp = api.createTextNote(todoRootNote.noteId, "New task", "")
return resp.note.noteId;
});
await api.waitUntilSynced();
await api.activateNewNote(taskNoteId);
}
});
Testing the functionality
Since we set the script to be run on start-up, all we need to do is to refresh the application.
Understanding how the script works
| This uses the Front-end API to create a icon in the Launch Bar, by specifying:
|
|
|
|
|
|
|
|
|
|
|