Skip to main content

Show toasts and modals

BetaThe plugin SDK and these pages are new. They change with each release, as developers use them and tell us what works.View as Markdown

Tell the user what your plugin did with a toast, or ask them to decide with a modal window. A toast appears for a few seconds and needs no answer. A modal stays until the user selects one of its buttons.

Use them only when the user needs to know. Good uses:

  • Settings were saved, or could not be saved.
  • A login worked, or failed.
  • An action the user asked for is done.

Show a toast​

Call pushToastMessage with a type, a title and a message:

index.js
this.commandRouter.pushToastMessage('success', this.strings.PLUGIN_NAME, this.strings.LOGIN_DONE);

The type sets the toast's colour and icon:

TypeUse it for
successAn action that worked
infoSomething the user should know, such as a login in progress
warningA problem the plugin worked around
errorAn action that failed

Take the title and the message from the plugin's i18n files, so they appear in the user's language. The template loads them into this.strings in onStart.

Show a modal​

1. Declare the permission​

In volumio-plugin.json, add ui:modal to permissions. Moderators read the permissions when they review the plugin.

volumio-plugin.json
"permissions": ["ui:toast", "ui:modal"]

2. Open the modal​

Send an openModal message with broadcastMessage. Every open Volumio web UI shows it:

index.js
this.commandRouter.broadcastMessage('openModal', {
title: this.strings.RESET_TITLE,
message: this.strings.RESET_MESSAGE,
size: 'lg',
buttons: [
{ name: this.strings.CANCEL, class: 'btn btn-info' },
{
name: this.strings.RESET,
class: 'btn btn-warning',
emit: 'callMethod',
payload: { endpoint: 'miscellanea/hello_volumio', method: 'resetSettings', data: {} },
},
],
});

Any button closes the modal. A button without emit only closes it.

3. Handle the answer​

A button with emit: 'callMethod' calls a method of a plugin. endpoint is the plugin's <type>/<id>, method the method's name, and data its argument. Add the method to index.js:

index.js
resetSettings() {
this.config.set('greeting', 'Hello from Volumio');
this.commandRouter.pushToastMessage('success', this.strings.PLUGIN_NAME, this.strings.RESET_DONE);
return libQ.resolve();
}

Check that it works​

  1. Install the plugin with npx --package=@volumio/plugin-sdk volumio-plugin deploy 192.168.1.20 ..
  2. Open the Volumio web UI and do what shows the toast or the modal.
  3. For a modal, select the button with emit: 'callMethod'. The toast from resetSettings appears.

Was this page helpful?