Run code when the position'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; layout.changed with Player.on
does not). Called with null when the panel there is unmounted, and also
when only the tabs changed (PanelSlot.panels: a panel added or
removed, another tab current). Errors go to Scope.onError.
When the sidebar should show but the window has no room for it, the
OSD says so. The listener runs on every change of the position,
whoever caused it. The player reports reason: "space" when
the preference is to show the sidebar but the window is too small.
plugin.panels.sidebar.onChange((state) => {
// `null`: no panel is mounted in the sidebar any more.
if (state?.reason === "space") void plugin.osd.show("Widen the window to see the playlist");
});
Show or hide the panel at this position: set the user's preference.
The new preference.
Resolves once the layout has the new preference, with state
refreshed.
The same as the user's menu item: the preference is remembered. Showing
may still leave the panel off screen (reason: "space"); in fullscreen,
true pops the sidebar overlay out at once.
The control bar disappears, as if the user had hidden it from the menu,
and stays hidden at the next start because the preference is
remembered. setVisible rejects with missing when no panel is in the
bottom bar, which this plugin treats as nothing to hide.
await plugin.panels.bottom.setVisible(false).catch((error: PluginError) => {
if (error.code !== "missing") throw error; // no bar mounted: nothing to do
});
Flip the user's preference, using the player's current value.
Resolves once the layout has the new preference.
Reads the state from the player first, so it is right even when the
copy does not follow the player. It is a switch, the same in every mode: in fullscreen a column
switched on is revealed by the pointer at the right edge, and is not popped
out by the toggle (setVisible(true) pops it out). Switching it off while
it is out slides it in at once.
Screen ▸ Control bar shows or hides the bottom bar and carries a check
mark while it is shown. toggle reads the player's current preference
first, so it is right even when nothing follows the layout; checked is evaluated
again after the command runs and follows state.
plugin.commands.add({
id: "toggle-bar",
path: ["@screen", "Control bar"],
// The user's preference, remembered across launches.
checked: () => plugin.panels.bottom.state?.preferred ?? false,
run: () => plugin.panels.bottom.toggle(),
});
Make a panel's tab the current one, without showing or hiding the position.
The manifest id of the plugin whose panel to show, one of PanelSlot.panels.
Resolves once the layout has the new current tab, with state
refreshed.
The sidebar holds the panels of several plugins as tabs (see Panels.mount); this switches which one it shows, like a click on its tab. To show this plugin's own panel, use Panel.show. The bottom bar has one panel: activating it changes nothing.
A command makes the playlist the sidebar's current tab without showing
or hiding the sidebar, like a click on its tab. activate takes the
manifest id of the plugin whose tab to show and rejects with
missing when that plugin has no panel there.
plugin.commands.add({
id: "to-playlist",
title: "Show the playlist tab",
run: () => plugin.panels.sidebar.activate("vestra.playlist"),
});
Float the sidebar panel in its own window, or attach it back.
true to float, false to dock.
Resolves once the layout has changed, with state refreshed.
The sidebar moves into its own window, or back into the main window
when it already floats. state says whether it is detached now;
setDetached resolves once the layout changed, with state refreshed.
const sidebar = plugin.panels.sidebar;
await sidebar.setDetached(!sidebar.state?.detached);
ReadonlystateThe current state; null while no plugin has a panel there. With
sidebar tabs it is the whole position's: shown,
hidden and floating apply to all tabs, which PanelSlot.panels
lists.
ReadonlypanelsThe position's panels in tab order: the sidebar's tabs, the bottom
bar's one panel; null while there is none (as state). Refreshed with state.
The sidebar position: a PanelSlot that can also float in a window of its own.
Remarks
Detached, the sidebar panel is shown in a separate window (300×408 by default, at least 300×250) with the panel's
title. The plugin's properties and callbacks stay the same, but the window holds a new instance of the component. Closing the floating window (its close button or the standard close keys) is the same assetVisible(false).Example: Add a "Detach sidebar" item
Tools ▸ Detach sidebar floats the sidebar in its own window and docks it again, with a check mark while it floats.
setDetachedmoves all the sidebar's tabs; the floating window holds new instances of the panels, which keep the plugins' properties and callbacks.Since
1.0.0