Release the resource. Resolves once the player confirmed the release (or immediately for purely local resources). Never rejects.
A "Turn feature off" item removes the feature's own menu item at once,
before the plugin stops. dispose takes the command out of the menu and
the binding table and resolves once the player confirmed it; the id can
be added again later.
const extra = plugin.commands.add({ id: "extra", path: ["Tools", "Extra"], run() {} });
plugin.commands.add({
id: "extra-off",
path: ["Tools", "Turn extra off"],
run: () => extra.dispose(), // never rejects
});
Replace some state fields (values or functions). Last write wins.
Only this command is evaluated again, not every binding and command of
the plugin. Several calls within one
microtask send one update. A function field makes the command take part in
the update passes from then on. A binding that reads a plugin variable
changed together with set outside a handler the SDK runs (a timer) is not
refreshed by it: call Scope.update or keep that variable in
Scope.state.
The Export item shows as busy with "Exporting…" as its reason while the
export runs, then returns to normal. set replaces only the fields it
names and the SDK sends the new state to the player; a busy command's
menu item and key do not run it again until it is set back.
const exportCommand = plugin.commands.add({
id: "export",
path: ["@video", "Export…"],
run: async () => {
exportCommand.set({ busy: true, reason: "Exporting…" });
try {
await runExport();
} finally {
exportCommand.set({ busy: false, reason: null }); // also on failure
}
},
});
ReadonlyidThe local id given in CommandOptions.id.
ReadonlyreadyResolves when the host has registered the command. Rejects with conflict
(path already taken), invalid or limit (more than 160 commands in this
plugin, or 1024 in the whole player). You rarely need to await it: the
refusal goes to Scope.onError. During activation the SDK, in the
plugin's process, logs the refusal with the command id and the player's
message, skips the command and lets the rest of the plugin activate;
the error reaches onError once
activation completes, so a listener added anywhere in activate hears it.
startPlugin stays strict: there a refusal during activation fails it, so
tests show the bad declaration. Any other failure during activation
(no answer, for example) fails activation.
Only the player's answer is skipped. What Commands.add checks
itself still throws from add (an unknown @ menu id, more than 8
path segments, an order out of range, a malformed binding or one
listed twice, a bad button, a reason text of the wrong shape, an id
already declared), and fails activation unless the plugin catches it.
A registered command, from Commands.add. Disposing it removes it from the menu and the binding table; the id can be added again right away.
Remarks
The handle of one menu item and its keys. Its state (
enabled,checked,busy,reason) is bound: functions given to Commands.add or Command.set are evaluated again in every full update pass (after a player state change only if they read a changed field ofplugin.player.stateor Scope.state) and only changes reach the player; a command without functions is left out of the passes. Its title, path, bindings and button cannot change in place; dispose the command (or a child Scope) and add it again. Disposing it, its scope or stopping the plugin removes the menu item, its keys and its bar button.Example: Enable an item only while a file is open
Video ▸ Export… is greyed out until a file is open.
setreplaces theenabledfield with a condition, which the player evaluates itself at every change, so the item follows the player without further code, also while the plugin is stopped.See
Commands.add, Commands, menus and bindings
Since
1.0.0