Declare a command. It is registered and kept in sync; dispose() removes
it from the menu and the binding table, and the id may be added again.
Titles and paths cannot change in place: put changing items (track lists, presets) in a child Scope and rebuild it.
invalid synchronously for a malformed path (including an
unknown @ menu id), order or binding; conflict for an id this
plugin has already declared and not disposed.
invalid (ready rejects; during activation the SDK logs and
skips the command and the plugin activates, see Command.ready;
startPlugin fails) for a text the player refuses: an id, title, path segment, group or reason
that is empty, longer than its COMMAND_LIMITS bytes (a text value counted
by its English rendering), has a control character or whitespace at either
end, or an id with other characters than ASCII letters, digits, ., _
and -. TestHost refuses the same.
Playback ▸ Pause (and Ctrl+P) pauses and resumes, shows a check mark
while paused and is greyed out when nothing can be paused. The player
calls run when the user picks the item or presses its key; enabled
and checked are plugin.when conditions the player evaluates
itself at every change, also while the plugin is stopped.
const { when } = plugin;
const toggle = plugin.commands.add({
id: "toggle-pause",
path: ["Playback", "Pause"],
order: 210, // position among the Playback menu's items
bindings: ["Ctrl+P"],
enabled: when.can("pause"),
checked: when.paused,
run: async () => {
const now = await plugin.player.refresh(); // the state now
await plugin.player.setPaused(!now.paused);
},
});
The keys of one of this plugin's own commands (its local id, as in
CommandOptions.id), written as the player's menus and command
palette write them: ["W"], ["Ctrl+B"], ["⌘B"] on macOS, arrows as
←. Read-only, and always what is bound now: the user's own keys
after a change in Keyboard Shortcuts, none when the user cleared them
or turned on Ignore Default Shortcuts, and none for a key another
command holds. Mouse bindings are left out, and so are Cmd
bindings outside macOS (as in the menus). The first label is the one
the menus show.
For key hints beside a panel's controls (KeyHint and the keys of
ToolTipArea in @vestra/widgets.slint). Read it in a
View.bind function and the view follows every change; or
listen with plugin.player.on("commands.keys", …) and read it there
(the SDK's copy already has the event's keys). The first read asks the
player, and until its answer arrives (a few milliseconds) every
command reads []; a binding that read it runs again then. That answer
is not an event: a player.on listener hears only the player's later
commands.keys events, so read the keys you start with in a bind
function, which runs again when the answer arrives, not only in the
listener.
The plugin's own commands, and the player's own as host/<id>
(host/volume-up, host/mute: the ids of
BUILTIN_COMMANDS
rows owned by host), for a panel that shows the player's keys beside its
own controls; an id the plugin has not added (or another plugin's) reads
[]. The whole binding table, every plugin's, is Bindings.list.
The Brightness row shows its two keys, W and E by default, as key caps
(KeyHint in ui/picture.slint). keys is read inside the bind function,
so the view gets the new labels whenever the user changes a key or
clears it (an empty list hides the cap).
const pictureWindow = plugin.windows.create("ui/picture.slint");
plugin.commands.add({ id: "brightness.down", path: ["@video", "Brightness −"], bindings: ["W"], run() {} });
plugin.commands.add({ id: "brightness.up", path: ["@video", "Brightness +"], bindings: ["E"], run() {} });
pictureWindow.bind(() => ({
// Read in bind: the view follows every key change; "" hides a cap.
brightnessDown: plugin.commands.keys("brightness.down")[0] ?? "",
brightnessUp: plugin.commands.keys("brightness.up")[0] ?? "",
}));
List every command the command palette lists, the player's own and every plugin's, with its state now. Built-in plugins only.
The palette's table as data: for a plugin that runs commands for the
user (an assistant, a macro recorder, a remote control) or shows how to
reach them (a tutorial that says which key opens a window). revision
changes whenever a command is added, removed or changes state, so a copy
with the same revision is still current.
A tutorial panel tells the user which key opens Subtitle Tuning. list
returns the palette's rows with their places and current keys; the
panel picks the row by its global id and shows its first key.
try {
const { commands } = await plugin.commands.list();
const row = commands.find((each) => each.id === "vestra.subtitles/tuning");
if (row?.keys[0]) await plugin.osd.show("Press {}", [row.keys[0]]);
} catch (error) {
// `builtin-only`: not a built-in plugin.
if ((error as PluginError).code !== "builtin-only") throw error;
}
Run any command the palette lists, as the palette runs it, for a request the user made. Built-in plugins only.
The command's global id, as CommandInfo.id:
<manifest id>/<local id>, host/<id> for the player's own.
ticket: from the user action this run is for.
step and of: this is step step of of (1-based), shown in the
on-screen line. then: the commands the ticket runs next, asked for
together with this one.
{ ran: true } once the command was started, or
{ ran: false, declined: true } when the user chose Don't Run.
Every run needs a ticket: the player mints one only for a user action
(PaletteLeadRun.ticket, Enter on the palette's lead row), so a
plugin cannot run commands on its own. The ticket ends with
PaletteLead.done, with the plugin's next lead run, when the
plugin stops, or 120 s after it was given or last used. The player
applies the palette's checks (enabled, not busy), shows an on-screen
line naming the plugin and the command (Vestra Player AI · 1/2 · Playback: Mute), and asks the user first (Run / Don't Run) before a
command declared CommandOptions.destructive, the player's Close
and Quit, anything in the Settings and Reset menus, and every command
of a plugin that is not built in. Runs are limited to 4 a second and 30
per ticket, and 120 a minute per plugin. The run is not added to the
palette's recent list.
A request of several commands names the rest of its plan in then on
its first run (since 1.7.16): if any command of the plan asks first,
the player asks once, before the first command runs, listing the whole
plan, and the later runs of the planned commands with the same ticket
do not ask again. Don't Run runs none of them. See
CommandRunOptions.then.
The user typed "reset the picture and mute" into the palette's lead
row; the plugin runs the two commands it chose for it. The ticket comes
with the lead's run event and covers every run of this request; done
ends it. The first run names the rest of the plan in then, so the
player asks once for both (Reset: Picture asks first) before anything
runs. A declined confirmation or a failure stops the request.
lead.onRun(async ({ ticket }) => {
const ids = ["vestra.video/video.reset", "host/mute"]; // chosen for the request
try {
for (const [index, id] of ids.entries()) {
const result = await plugin.commands.run(id, {
ticket,
step: index + 1,
of: ids.length,
// The first run names the rest of the plan.
...(index === 0 ? { then: ids.slice(1) } : {}),
});
if (!result.ran) break; // the user chose Don't Run: nothing ran
}
} catch (error) {
// `disabled`, `busy`, `missing`, `ticket` (expired), `limit` (rate).
await plugin.osd.show("Stopped: {}", [(error as PluginError).message]);
} finally {
await lead.done(ticket);
}
});
busy (rejects) The command is busy, or another confirmation
or approval sheet is waiting for the user's answer.
plugin.commands: menu commands with default bindings. Needscommands.Remarks
A command is one action of the plugin with a menu item (
path), default keys (bindings), optionally a bottom-bar button (button) and a state the menu shows (enabled,checked,busy,reason). The player owns the menu, the binding table and the user's key overrides: it callsrunwhen the user picks the item, presses a key or clicks the button. Commands of all plugins merge into the player's menus by their English path keys. Registration is asynchronous:addreturns at once, and Command.ready reports the player's answer (during activation the SDK logs a refusal and skips that command;startPluginfails on it). Whataddchecks itself throws fromadd.Example: Add a menu item with a default key
Tools ▸ Say hello, or Ctrl+H, shows a greeting.
adddeclares the item; the player callsrunwhen the user picks it or presses its key, and the user can change the key in the player's key settings.See
Command, CommandOptions, Commands, menus and bindings
Since
1.0.0