Add Toast Notifications API for Plugin Developers

Summary

Request the addition of a toast notification API to allow plugin developers to notify users of completed actions in a non-intrusive manner.

Motivation

Toast notifications provide timely and unobtrusive feedback. For example, my plugin summarizes notes using LLMs, and it would be useful to show a toast message like "Summary completed" upon task completion.

Proposed Solution

Add an API method for plugins to trigger toast notifications with customizable options for message content, duration, and position.

Benefits

  • User Experience: Provides immediate, non-disruptive feedback.
  • Plugin Functionality: Enhances interactivity and responsiveness.
  • Consistent UI/UX: Ensures uniform notification design across the app.

Example Use Case

joplin.plugins.on("noteSummarized", async (summary) => {
    joplin.notifications.showToast({
        type: 'success',
        message: 'Summary completed!',
        duration: 3000,
        position: 'top-right'
    });
});

Conclusion

Adding toast notifications will improve Joplin's usability and interactivity. This feature will be valuable for enhancing user experiences through plugins.

Thank you for considering this request.

6 Likes

Thanks for writing the detailed spec. It will be available from the next version with this API:

7 Likes

Great! Thank you.

But after I tried the latest dev framework (npm list -g generator-joplin = v3.2.1), there still says,
"Property 'showToast' does not exist on type 'JoplinViewsDialogs'."

So, how can I get the new version with this API? Thanks.

It should work, but a temporary workaround would be await (joplin.views.dialogs as any).showToast(.... to disable type-checking. I will check why it hasn't been exported properly

Thank you. Your "temporary workaround" worked well.

In addition, another bug (maybe?) is here:
If all parameters ('message', 'duration', and 'type') remain unchanged, subsequent toast notifications will not be displayed. A new toast will only appear if at least one of these parameters is modified.

I found an unconventional solution:

await (joplin.views.dialogs as any).showToast({message:'Finished', duration:3000+(Date.now()%500), type:'success'});

Hope this will help.

Thank you for reporting this! I'm linking a related pull request:

1 Like

Another bug report.

The bug can be consistently reproduced with the following steps:

  1. Show and dismiss any toast notification (created using this API),
  2. Enter the options window by clicking on Tools > Options,
  3. Close the options window.

After these steps, the last toast notification will appear again.

I'm also getting this bug.

Also, the issue with the notification not reappearing hasn't been fixed for me by using the timestamp. I still only see the notification once. Do you also still experience this issue?