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
});
A child scope; disposing it releases only what was created through it. The child is itself owned by this scope.
A "Live stats" feature opens a window and starts a timer; turning it off releases both together. Everything made through the child scope, and cleanups registered on it, go when the child is disposed; the parent scope is untouched.
let live: Scope | null = null;
plugin.commands.add({
id: "live-stats",
path: ["Tools", "Live stats"],
checked: () => live !== null,
run: async () => {
if (live) {
await live.dispose(); // closes the window, stops the timer
live = null;
return;
}
live = plugin.scope();
const statsWindow = live.windows.create("ui/stats.slint");
const timer = setInterval(() => live?.update(), 1000);
live.onDispose(() => clearInterval(timer));
await statsWindow.show();
},
});
Adopt an existing handle: it is disposed together with this scope.
Any Disposable, for example a handle created through another scope.
item itself, for chaining.
A filter made through the root scope is withdrawn when a child feature
ends. add hands an existing disposable to this scope, which then
disposes it with its own handles; it returns the same handle for
chaining.
const feature = plugin.scope();
const blur = feature.add(plugin.video.filter("blur")); // now ends with `feature`
blur.set([{ kind: "gblur", sigma: 4, steps: 3 }]);
Run cleanup when this scope is disposed (for example clearInterval
or closing a socket). It may be async; errors are logged.
A handle that cancels the registration early (without
running cleanup).
A once-a-second refresh runs as long as the plugin does. onDispose
runs the cleanup when the scope is disposed, which for plugin is
when the player stops the plugin, so the timer never outlives it.
const timer = setInterval(() => plugin.update(), 1000); // re-evaluate bindings
plugin.onDispose(() => clearInterval(timer));
The plugin writes its cache file at once when the player crashed or was
killed, instead of waiting for the next periodic save. The cleanup may get
a DisposeInfo: stopping says the plugin itself stops (not a child
scope), reason why.
plugin.onDispose((info) => {
// The player is gone: ask it nothing, keep what is local.
if (info?.reason === "host-lost") saveCacheNow();
});
In the player (and in TestHost) the cleanup is called with one argument,
a DisposeInfo: whether the plugin stops, and why. A cleanup that
takes no argument works as well; a function with optional parameters
of its own that is passed directly
(onDispose(controller.abort.bind(controller))) now receives the
DisposeInfo as its first argument: wrap it (() => controller.abort())
when that matters.
Errors thrown by handlers that the SDK invoked (command run, window and
panel callbacks, onChange listeners) in this scope. Without a listener
they go to the parent scope, and finally to the plugin log.
Rejections of async handlers count too, and so do failures of
registrations made after activation (a command whose ready rejects,
a property write the player refused).
When a menu command, a window callback or a listener of the plugin fails, the user sees why. The SDK catches what those handlers throw (and their rejected promises) and passes it here instead of only logging it; the message is data in a translated template.
plugin.onError((error) => {
void plugin.osd.show("Bookmarks: {}", [error.message]);
});
Re-evaluate every bound value (bind() functions and command state
functions) and send what changed. The SDK already does this after each
handler it invokes and when that handler's promise settles; call it after
changing state from your own timers or between awaits of a long task.
Several calls within one microtask are merged into one pass.
A progress label moves while a long download runs, not only when it
ends. The SDK re-evaluates bound values after each handler and when its
promise settles; state changed between the awaits of a long handler
shows only after an explicit update().
let done = 0;
downloadWindow.bind(() => ({ progress: done }));
downloadWindow.on("start", async () => {
for (let part = 0; part < 10; part++) {
await downloadPart(part);
done = part + 1;
plugin.update(); // send `progress` now, not when the handler ends
}
});
Plugin-owned state that bound values follow by themselves: reading a
field in a bind function or a command's state function records it,
and writing that field re-evaluates exactly those readers.
The fields and their first values: a plain object.
The tracked object.
Returns an object of the same shape as initial (a copy of its own
fields; initial itself is not tracked). A read inside a
View.bind function or a CommandOptions field given as a
function is recorded like a read of plugin.player.state; anywhere
else (a handler, an onChange listener, a timer) it is a plain read,
and writing there is how a handler updates what is bound. A write of a
field (or a new field, or delete) schedules one
update pass for the microtask turn, however many fields change, and that
pass evaluates only the readers of what changed, not every binding and
command as Scope.update does. Writing a value equal to the
current one (Object.is) changes nothing.
Tracking is one level deep: a field holding an object or array is
compared by identity, so changing something inside it is not seen.
Replace the object instead (st.list = [...st.list, item]). Do not
write a field from a bind function that reads it: each write runs the
function again; the SDK stops such a loop after 100 passes in a row and
reports it to Scope.onError once (limit). The limit counts
passes, not loops: a chain of bindings that is not a loop but deeper
than 100 (each writing a field the next one reads) is cut the same
way: what the dropped pass would have evaluated waits for the next full
pass (after a handler, or Scope.update). Keep derived values in
one function instead of chaining fields.
The object is a Proxy: spread, Object.keys and JSON.stringify give
its values; structuredClone does not take it (clone { ...st }). It
belongs to this scope: once the scope is disposed it is a plain object,
whose reads and writes still work but are no longer recorded and
schedule no pass (as other handles of a disposed scope go quiet).
update() stays for state the SDK cannot see.
A panel shows whether the current file has video once an asynchronous
check answers. The answer is written to a tracked field; only the
bind function that reads it runs again and sends the new value, with
no plugin.update() and no pass over every other binding.
const st = plugin.state({ video: null as boolean | null });
bar.bind(() => ({ keyframes: st.video === true })); // reads st.video
plugin.player.on("source.ready", ({ state }) => {
if (state.source === null) return;
void hasVideo(state.source).then((video) => (st.video = video)); // re-runs the bind above
});
Makes a trigger: a condition the player keeps and evaluates, and the
functions it calls when the condition becomes true and false, also
waking the plugin from standby. Called only in the synchronous part of
activate() (before its first await). Without a name the trigger is
known by its place among the unnamed ones, and a condition it was
given is cleared when the plugin is upgraded; with a name it is known
by the name and survives an upgrade. At most 64 per plugin.
Optionalname: string
Unique within the plugin, 1–64 characters.
Error without a code (throws) Called after the synchronous
part of activate(), or on a scope made with plugin.scope() (a
trigger is the plugin's: its condition outlives any scope).
A menu item pauses playback 45 minutes later. The trigger is named,
so its condition stays with the player through standby and an update,
and enter disarms it before pausing.
const { when, player, commands } = plugin;
const alarm = plugin.trigger("sleep").enter(async () => {
alarm.off(); // fire once: the player forgets the condition
await player.setPaused(true);
});
commands.add({
id: "in45",
path: ["Tools", "Sleep in 45 Minutes"],
run: () => alarm.firesOn(when.time({ min: Date.now() + 45 * 60_000 })),
});
ReadonlycommandsMenu commands and their default bindings (commands).
ReadonlywhenConditions on the player's own state for a command's enabled and
checked: the player evaluates them, so the menu follows playback even
while the plugin is stopped. See When.
ReadonlywindowsTool windows from .slint files.
ReadonlypanelsDocked panels: bottom bar, sidebar and backdrop.
ReadonlydialogsNative file dialogs and confirmation alerts.
ReadonlyplayerPlayback state and controls.
ReadonlyvideoVideo processing: this plugin's filter chain, the display layer, the GPU render options, this plugin's shaders, the GPU's video upscaler and motion smoothing. The filter chain follows the player by itself while it exists (it applies when a video becomes ready).
This plugin's video filter chain named id (unique within the
plugin). Nothing is sent until the first set().
Local name of the chain.
A VideoFilter owned by this scope.
The display layer. The first plugin to call
it owns the layer; another plugin's view fails with conflict until the
owner disposes or stops.
The GPU renderer's options, owned like the
display layer. Under software rendering the handle is failed with
unsupported after the player's first answer, and onError hears it.
This plugin's own GPU shaders named id (default "shaders"). Unlike render(), every plugin
may hold shader handles at the same time; the player joins their lists.
Nothing is sent until the first set().
Optionalid: string
Local name of the handle, 1–128 bytes, unique within the plugin.
A VideoShaders owned by this scope.
Readonlyupscaling: VideoUpscalingThe GPU's video upscaler (NVIDIA RTX Video Super Resolution on Windows): whether it works here and why not, and turning it on or off for this plugin.
Motion smoothing with one GPU vendor's frame-rate converter: whether it works here and why not, and this
plugin's mode. amd is AMD AMF's on Windows; nvidia is NVIDIA's
(FFmpeg's fruc_vulkan, GeForce RTX 30 and newer, on Windows; an
older player reports engine for every mode).
The converter: "amd" or "nvidia".
A VideoMotion for that converter.
ReadonlyaudioAudio processing: this plugin's filter chain and delay (it follows the player as VideoFilter does).
This plugin's audio filter chain named id (unique within the
plugin). Nothing is sent until the first set().
Local name of the chain.
An AudioFilter owned by this scope.
ReadonlysubtitlesSubtitle tracks, uploads and style.
ReadonlymediaFrozen snapshots and offline exports.
ReadonlyresolversPage-URL to stream-URL resolvers.
ReadonlypackagesThe installed plugins; validation, installs.
ReadonlyosdOn-screen messages over the video.
ReadonlypaletteThe command palette's lead row (palette.lead, built-in plugins only).
ReadonlyhostThe player's own core playback actions (commands).
ReadonlyclipboardThe system clipboard (clipboard).
ReadonlypowerKeeping the computer awake while playing.
Readonlytoolsffmpeg / ffprobe, run by this plugin's process.
ReadonlystorageJSON settings files in dataDirectory.
ReadonlysystemShow files in the file manager, open files and links.
ReadonlysecretsSmall secrets in the system's secret store (secrets).
Readonlympvmpv's own commands and properties, sent as they are (mpv).
ReadonlywindowThe main window: fullscreen, video area, size, level, pointer hiding.
ReadonlyappThe player's version and components, and the system it runs on.
ReadonlyrenderingGPU or software rendering: read the choice, change it.
ReadonlybindingsEvery command's bindings and the user's overrides.
ReadonlyuiRuntime images for Slint image properties.
ReadonlytimelineMarks on the seek bar, merged from every plugin's layer.
ReadonlydropsFiles dropped on the video area, by extension.
ReadonlyappearanceThe player's palette and the saved interface language.
Readonlyi18nThe interface language of this run (read-only).
ReadonlysettingsPages in the player's options window.
Readonly ExperimentalwireDirect messages to the player: requests by method name, raw events, direct property writes, bare command registrations. Experimental: the wire protocol is not semver; this member changes with versions. See Wire.
ReadonlyidThe manifest id, e.g. "community.bookmark".
ReadonlydataA writable directory for this plugin's own files (settings, caches,
remembered folders), created by the player before it starts the plugin.
Each installation has its own directory: it is kept across restarts,
disabling and upgrades, and a reinstall of the same id from a different
source gets a new, empty one. It is deleted only by
packages.uninstall(id, { removeData: true }).
The path's format is not part of the API: do not derive another
plugin's directory from it (a plugin manager reads
PluginInfo.dataDirectory). Write files atomically (to a
temporary name, then rename); for JSON settings prefer
Scope.storage. Throws unavailable when the player provided
none. See Store a plugin's data.
ReadonlystopWhy the player stops this plugin: set when the stop begins, before any Scope.onDispose cleanup runs. See StopReason.
The object the player passes to a plugin's
activate: the root Scope, plus the plugin's identity and data directory.Activation: the player starts one Node process per plugin, reads the initial player, window and timeline state, then calls
activate(plugin). Registrations started during activation (commands, panels, resolvers, subscriptions) do not need to be awaited: the plugin is reported ready once they all succeed, and activation fails ifactivatethrows or any of them fails. A command declaration the player refuses is the exception: the SDK logs and skips it, itsreadyrejects and Scope.onError hears it, the rest of the plugin activates (startPluginstill fails on it). The entry module must default-exportactivate. Do not await a run of your own command or a callback of your own view insideactivate: the player holds them until the plugin is ready, soactivatewaits until the start timeout (60 s) and the plugin stops withfailed.Stopping: the player first revokes everything the plugin owns on its side (menus, windows, panels, filters, subtitle layers, snapshots, jobs, resolvers, streams); pending requests then fail with
disabledand the root scope is disposed for local cleanup (timers, signals, sockets). A process that has not exited after its grace is killed: 5 s (300 ms after a fault); at quit all plugins together get 1 s. Media the plugin opened with Player.open keeps playing.Example: Write a minimal plugin with one menu item
Tools ▸ Say hello, or Ctrl+H, shows "Hello from" and the plugin's id. The player imports
main.ts, calls its default export with thePluginobject, and keeps the registrations made during activation; the manifest says only who the plugin is.Remarks
The root scope: disposing it is what stopping the plugin does. Besides the modules of Scope, it carries the plugin's
idand itsdataDirectory.See
Tutorial
Since
1.0.0