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"),
});
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 bottom bar, the sidebar or the adjust column position (
plugin.panels.bottom,plugin.panels.sidebar,plugin.panels.adjust), independent of who mounted the panel there.Remarks
The position does not belong to the plugin that mounted the panel: any plugin may read and toggle it, so a "Show playlist" command can live in a different plugin than the playlist. The player remembers the sidebar's visibility, width, detached state and floating window position across launches.
stateis read when first used. While anonChangelistener exists it follows every change (the user, other plugins, the window size), and it takes eachlayout.changeda Player.on listener hears; otherwise it refreshes only after this plugin's own changes.Example: Add a "Show sidebar" item that works with any sidebar panel
Tools ▸ Show sidebar shows or hides the sidebar, whichever plugin's panel is in it, with a check mark while it is shown. The position does not belong to the plugin that mounted the panel:
stateisnullwhile nobody has a panel there (the item is disabled then), andtoggleflips the user's remembered preference.See
Panels, SlotState
Since
1.0.0