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
});
Handle a Slint callback.
The Slint callback's name, in camelCase
(toggleEffect) or as written in Slint (toggle-effect).
Receives the callback's arguments.
A handle that removes this handler (if it is still the current one for the name).
The handler receives the callback's arguments as JSON (struct fields
spelled as in Slint). It may be async. An error it throws, or a rejection
of its promise, goes to Scope.onError. After it returns, and
again when its promise settles, the SDK runs an update pass, so state it
changed reaches bound properties without further calls (state changed
after an await appears only when the promise settles; call
Scope.update to show it earlier).
Calling on again with the same name replaces the handler. A callback
the plugin has no handler for is ignored.
Tool windows forward only the callback names bound when the window
opens: bind every name before the first Window.show. While the
window is open, binding a new name throws; after a close the next show
registers the names bound by then. A name the Slint file does not declare
makes show reject. Panels and settings pages forward every
callback of their bridge global, so bind whenever you like.
Error without a code (throws) On an open Window, for a
name that has no handler yet.
Moving the window's brightness slider updates the plugin's value, and
the slider shows it back. The Slint callback brightness-changed
reaches the handler with the slider's value as JSON; after the handler
returns, the SDK runs an update pass and bind sends the new value.
Callbacks of a tool window must be bound before its first show.
const picture = plugin.windows.create("ui/picture.slint");
let brightness = 0;
// camelCase here, `brightness-changed` in the Slint file.
picture.on("brightnessChanged", (value: number) => {
brightness = value;
});
picture.bind(() => ({ brightness }));
await picture.show();
Write properties now, even values that did not change.
Each value given is sent once with the next write, even if it equals the
last value sent. That makes set the way to pull a control back to the
model value after the user moved it, or to put a one-off value (a
document, an image) on screen. While the view is not open (a window
before show, a panel before ready) the values are kept and become its
initial properties.
Do not set a property that a View.bind function also returns:
the next update pass replaces the set value with the bound one.
On a view nothing was bound to, set alone writes: each value is sent
whole, a large list in parts, one write in flight per view; the SDK neither
compares nor turns lists into row patches, and the view takes no part in
update passes. From the view's first View.bind on, set values go
the bound way: a list that differs from the one sent is sent as a row patch
where one applies.
A property the plugin writes directly (WireView.write) cannot be
set: one track per property. Otherwise it never throws. A write that
fails is retried with back-off and reported to Scope.onError (the
first failure of a run of failures; the message names the property). A
value over the limits of PropValue fails with limit. As an
initial property (written while the view is not open) it makes
Window.show reject; a panel or settings page still opens without it
(the property keeps its default) and the failure goes to the plugin's
onError.
invalid (throws) A property of props is written directly
with WireView.write ("property rows is written directly;
bind it or write it, not both"); nothing of props is kept.
Choosing "Custom" snaps the drop-down back to the last real preset.
The plugin cannot read a property back, only hear the callback; set
sends the value even though it equals the one sent before, which is
what pulls a control the user moved back to the plugin's value.
const presetsWindow = plugin.windows.create("ui/presets.slint");
let presetIndex = 0;
presetsWindow.on("presetChosen", (index: number) => {
if (index > 2) presetsWindow.set({ presetIndex }); // "Custom" is not a preset
else presetIndex = index;
});
Keep properties equal to a function of the plugin's state.
Returns the properties, by name.
A handle that stops this binding (the values last sent stay).
The SDK calls props in every update pass (and right after bind) and
sends the values that differ from the ones it sent last; a view takes part
in the update passes from its first bind on. After a change of the player
state alone it calls props only if it read a field of
plugin.player.state (or of a Scope.state object) that changed; a
full pass follows after each handler, on Scope.update and at least
once a second while the player state keeps changing. Because an unchanged
value is not sent again, text the user typed into an in-out property
stays until the plugin's value for it changes.
Keep the function quick and synchronous: it runs often. An error it throws is reported to Scope.onError and the other bindings still run. A view can have several bindings; when two return the same name, the one bound later wins.
A bound array is sent as row patches: only the rows whose value changed in
the plugin. So Slint code must not write into its rows
(rows[i].selected = true): that row keeps the Slint-side value until the
plugin's value for it changes. Send a callback and change the row in the
plugin instead. In a long list, return each unchanged row as the same
deep-frozen object (Object.freeze on it and on every object and array in
it): such a row is encoded once, not in every pass.
Never throws. Writes that fail are not repeated until the value changes,
and are reported to Scope.onError like a failed View.set (a
value over the limits of PropValue: limit). A property the plugin
writes directly (WireView.write) is left out of what the function
returns, reported once to onError with invalid: one track per property.
The status window always shows the current file and enables its seek
controls only for seekable sources. The SDK calls the function right
away, again in every full update pass (after each handler) and after
each change of source or can while a stream keeps
plugin.player.state following the player, and sends only the values
that changed. The stream is opened with the window and stopped when it
closes.
const status = plugin.windows.create("ui/status.slint");
status.bind(() => ({
title: plugin.player.state.source ?? "Nothing playing",
canSeek: plugin.player.state.can.seek,
}));
await status.show();
const feed = plugin.player.stream(() => {}); // while it is open
status.onClose(() => feed.stop());
Run code when this panel's state changes.
Receives the new state.
A handle that removes the listener.
The listener runs on every change, whoever caused it (it keeps the
plugin running while it exists). Called with null when the panel is
unmounted. Errors go
to Scope.onError.
The plugin logs when the user switches the sidebar to another plugin's
tab, for example to pause work the list does. The listener runs on
every change. reason: "otherTab" exists only in a
panel's own state: the SDK sets it when the sidebar's current tab is
another plugin's (the position's state never has it).
const panel = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
panel.onChange((state) => {
if (state?.reason === "otherTab") console.error("list in a background tab");
});
Show this panel: make its tab the current one and show its position.
Resolves once the layout shows the panel's tab, with state
refreshed.
Sets the position's preference like PanelSlot.setVisible(true)
(remembered; in fullscreen the sidebar overlay pops out). Waits for
Panel.ready first.
The errors of Panel.ready (rejects) The mount failed.
A command shows the List tab: it becomes the current tab and the
sidebar is shown, and the preference is remembered. show waits for
the mount first, so it can run right after mount.
const list = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
plugin.commands.add({ id: "show", title: "Show the list", run: () => list.show() });
Show this panel, or hide its position when it is shown.
Resolves once the layout has changed, with state refreshed.
Reads the state from the player first. When the position is shown
(preferred) and this panel's tab is the current one, it hides the
position; otherwise it switches the position on at this panel's tab: a
panel in a background tab comes to the front instead of the sidebar
closing. It is a switch, the same in every mode, like the player's own
Alt+1…4 and Adjustments and Effects: in fullscreen a column switched on is
revealed by the pointer at the right edge, not popped out
(Panel.show pops it out), and one switched off while out slides in
at once. A "Show list" command checked by state.preferred && state.active
matches it. Waits for Panel.ready first.
The errors of Panel.ready (rejects) The mount failed.
F6 and Screen ▸ List show the List tab, or hide the sidebar when the
list is already in front. toggle reads the player's state first:
it hides the position only when it is shown and this panel's tab is
the current one, otherwise it shows the panel.
const list = plugin.panels.mount("sidebar", "ui/list.slint", { title: "List" });
plugin.commands.add({
id: "list",
path: ["@screen", "List"],
bindings: ["F6"],
// Checked while the sidebar is shown with this list in front.
checked: () => (list.state?.preferred ?? false) && (list.state?.active ?? false),
run: () => list.toggle(),
});
Keep the panel on screen while the user works in it.
The locks to change; omitted ones keep their value.
In fullscreen the bottom bar shows only while the pointer is in the bar's own band at the bottom of the screen: at once when the pointer enters it, hidden 500 ms after it leaves (keys and pointer motion elsewhere do not reveal it), and the fullscreen sidebar overlay collapses when the pointer leaves it. A lock keeps the bar shown. Set a lock while a text field has focus, a drag is in progress or a popup is open, and clear it afterwards. Locks are merged with the earlier ones; the last value of each wins. The player already locks a panel while the pointer is over it. No effect on the backdrop.
Never throws: a failed write is reported to Scope.onError.
In fullscreen the bottom bar stays visible while the user types in
its search field, instead of hiding when the pointer leaves it. The
Slint side reports the field's focus through a callback, and
setInteraction sets or clears the focused lock; other locks keep
their values.
const panel = plugin.panels.mount("bottom", "ui/bar.slint");
panel.on("searchFocused", (focused: boolean) => panel.setInteraction({ focused }));
Pop up a menu of this plugin's commands at a point in the panel.
At most 32 commands of this plugin, or null for a
separator.
Where to open it, in the window's logical pixels: in Slint,
(self.absolute-position.x + self.mouse-x) / 1px (and the same for
y).
Logical pixels from the window's left edge.
Logical pixels from the window's top edge.
Resolves once the menu is open (not when the user picks).
A one-level menu, styled like the main menu (check marks, shortcut text),
in the window that shows the panel. Picking an item runs that command;
null is a separator. Commands without a menu path work too, which
makes context-only commands possible. Call it when the right button is
released, as the main menu does. Waits for Panel.ready first.
unavailable (rejects) The panel is not on screen (also: its
sidebar tab is not the current one), or it is the backdrop.
The errors of Panel.ready (rejects) The mount failed.
Right-clicking the list opens a menu with "Select the first item" and
"Remove the selected item". The Slint file passes the pointer position
in window pixels with its context-menu callback; showMenu opens the
plugin's commands there, and picking one runs that command.
// Callbacks of the bridge global; `bind` above sends the new selection.
panel.on("select", (index: number) => (selected = index));
// x and y: the pointer in window pixels, from the Slint file.
panel.on("contextMenu", (x: number, y: number) =>
panel.showMenu([first, null, remove], { x, y }),
);
Receive the files dropped on this panel.
Receives the paths in the order the file manager gave them, the point in panel coordinates (logical pixels from the panel's top-left corner) and the keys held.
A handle that removes the listener.
Covers the docked panel and the floating sidebar window. While a listener exists, drops on the panel come here as one group (not split by extension) instead of going to the Drops providers. Drops on tool windows and the Options window are ignored; in fullscreen, the bottom bar floats over the video and drops there count as drops on the video area.
Files dropped on the Files panel are added to its list. While the
listener exists, drops on the panel come here as one group instead of
going to the drop providers; after the listener returns, the SDK runs
an update pass and bind sends the longer list.
const files: string[] = [];
const panel = plugin.panels.mount("sidebar", "ui/list.slint", { title: "Files" });
panel.bind(() => ({ rows: files }));
panel.onDrop(({ paths }) => {
files.push(...paths); // in the order the file manager gave them
});
ReadonlyreadyResolves once the player has mounted the panel; rejects when the mount failed.
When the file compiles (player 0.9.0). A panel shown at once (the
bottom bar, the backdrop, the current tab of an open sidebar or adjust
column) is compiled before ready settles: a file that does not compile
rejects ready with ui-prepare. A tab mounted in the background (a
sidebar tab that is not current, any tab of a closed column) compiles
nothing at the mount, and ready resolves. Its file is compiled when the
tab is first shown; the adjust column compiles its first tabs (up to 4,
the current one among them) when it opens, and a tab mounted among them
while it is open right after its mount. A failure then is not a
rejection: it goes to Scope.onError as a ui-prepare error, and
the tab stays empty until the plugin mounts the panel again (disposes it
and mounts it anew, or restarts). So a broken file in a background tab
does not fail activation; show the tab (PanelSlot.activate) to
see its compile result.
Mounts made while activate runs must succeed before the plugin is
ready: a rejection fails activation, except conflict for a taken
position (below), which the player and TestHost
do not count: the plugin runs without its panel, its commands and keys
work, and the player shows the refusal (an OSD message,
PluginInfo.warnings and the text in PluginInfo.error).
Later failures also go to Scope.onError.
A second sidebar panel is not refused: it resolves as another tab (see
Panel.state). Built-in plugins mount first at start-up, so the
playlist's tab is first and a built-in panel keeps its position. The
sidebar takes any number of tabs; the strip shows the tabs that fit and a
» menu lists all of them. A plugin whose sidebar tab is in the
background, and that holds nothing else that keeps it running, goes to
standby when idle; showing the tab starts it again (see
Panel.state).
ui-prepare (rejects) For a panel shown at once: the Slint file
does not compile, or a bound property is not declared on the bridge
global; message has the diagnostics. For a tab mounted in the
background the same failure goes to Scope.onError when the tab is
first compiled (above).
conflict (rejects) Another plugin's panel holds the bottom bar or
the backdrop (shown, or being mounted); message names the position and
the holder (「底栏已被 vestra.playback 使用」). Not an activation failure. Never
for the sidebar.
ReadonlystateThis panel's state: its position's, and whether its tab is the current
one; null until Panel.ready resolved (and after dispose).
Read when first used; while an onChange listener exists it follows
every change (the user switching tabs, other plugins, the window size),
otherwise only this plugin's own changes. A sidebar panel in a background tab
has active: false, effective: false and reason: "otherTab".
A background tab does not keep the plugin running. If the panel is all that
keeps it running, the plugin goes to standby after the idle time (stop
reason idle): the player keeps its tab, with its title, in the strip and
the » menu. When the user shows the tab, the player starts the plugin
again; activate runs and mounts the same panel (same file and component),
which takes the tab over, and Panel.ready resolves again. Anything
the plugin kept only in memory is gone: restore the view from storage
(session storage survives standby). While it is in the background, the
player may also unload the panel's component (a column keeps at most 4
panels loaded) and make a new instance from the bridge properties last
written when the tab is shown again.
A panel in the player's main window, made by Panels.mount.
Remarks
Properties and callbacks live on the file's bridge global (see Panels). Unlike a tool window, a panel forwards every callback of the global, so View.on has no "bind before show" rule.
Life cycle.
mount()returns at once; in the next microtask the SDK sends the mount with every property bound or set so far. The player compiles each panel's file on its own, when the panel is first shown (see Panel.ready), and puts it in its position without rebuilding the main window: mounting or unmounting a panel leaves the other panels as they are. A panel keeps its component instance while its place exists, so a switch back to its tab finds it as it was. It gets a new instance when its place is made again (its column closed and opened, the column's fullscreen overlay, the sidebar moving to or from its floating window) and when the player unloaded it to make room (a column keeps at most 4 panels loaded) and shows it again. A new instance starts with the bridge properties last written, but state kept only inside the component (a scroll position, a property the plugin never writes) starts over: keep what matters in bridge properties. Each panel's file is compiled with its own globals: two panels that import the same file do not share a global.dispose(), disposing the scope or stopping the plugin unmounts it.Testing:
host.mounted()of@vestra-player/sdk/testinghas the panel'sslot,propsandemit(callback, ...args).Example: Mount a sidebar list with a right-click menu (examples/panel-menu)
The sidebar gets an "Example list" tab whose rows can be selected and have a context menu.
mountreturns at once and the player adds the panel as a tab;bindkeeps the rows and the selection on the panel's bridge global, and thecontext-menucallback opens a menu of the plugin's commands where the user clicked.ui/panel.slint:See
Panels.mount, PanelSlot, Example: Panel menu, Example: Adjust panel
Since
1.0.0