@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface Window

    A tool window: a separate operating-system window drawn from one of the plugin's .slint files, made by Windows.create.

    What it is. A top-level window with its own title bar: the user can move it, resize it (if the Slint file allows) and close it. It is not modal and not attached to the main window: playback and the main window keep working while it is open. Its title, size and content come from the Slint Window component (title, width or preferred-width…); the player applies its palette and the system font before the window appears. The system chooses its position; the player does not remember it. MainWindow.setAlwaysOnTop also floats tool windows.

    Life cycle.

    1. create() makes the handle; nothing is on screen.
    2. Bind callbacks with View.on and properties with View.bind or View.set.
    3. Window.show opens the window with those properties. Window.hide hides it and keeps its state.
    4. Window.close, or the user (title-bar button or the standard close keys), destroys the window instance; only the user's close calls Window.onClose. The handle stays usable: the next show() opens a fresh instance with the current properties.
    5. dispose(), disposing the owning scope or the plugin stopping closes it for good (without onClose); the id can then be used again.

    Command key bindings do not fire while a tool window has focus; handle keys in Slint (a FocusScope). The standard close keys never reach the window's Slint code.

    Testing: host.window(id) of @vestra-player/sdk/testing has the window's props, visible, emit(callback, ...args) and userClose().

    Playback ▸ Bookmark… opens the Bookmark window. create only makes a handle; the command's run calls show, which compiles the Slint file and opens the window with the bound properties the first time, and brings back the same window afterwards.

    const bookmarkWindow = plugin.windows.create("ui/bookmark.slint");
    // Re-evaluated after every handler and player change; only changes are sent.
    bookmarkWindow.bind(() => ({
    label: mark === null ? "No bookmark" : `Bookmark: ${mark.toFixed(1)} s`,
    canMark: player.state.position !== null,
    canJump: mark !== null && player.state.can.seek,
    }));
    // The Slint callbacks `mark` and `jump` of ui/bookmark.slint.
    bookmarkWindow.on("mark", () => {
    mark = player.state.position;
    return storage.session.set("mark", mark);
    });
    bookmarkWindow.on("jump", () => player.seek(mark!));
    plugin.commands.add({
    id: "bookmark.open",
    path: ["@playback", "Bookmark…"],
    order: 270,
    run: async () => {
    await bookmarkWindow.show(); // opens it, or brings back the open one
    feed ??= player.stream(() => {});
    },
    });

    A clock window ticks every second while it is open and stops costing anything once the user closes it. plugin.update() makes the SDK evaluate the bound time again from a timer; onClose runs only for the user's close, so the plugin stops the timer there.

    const clock = plugin.windows.create("ui/clock.slint");
    let timer: NodeJS.Timeout | undefined;
    clock.bind(() => ({ time: new Date().toLocaleTimeString() }));
    clock.onClose(() => {
    clearInterval(timer);
    timer = undefined;
    });
    plugin.commands.add({
    id: "clock",
    path: ["@screen", "Clock…"],
    run: async () => {
    await clock.show();
    // Re-evaluate `bind` once a second: bound values change only then.
    timer ??= setInterval(() => plugin.update(), 1000);
    },
    });

    1.0.0

    interface Window {
        dispose(): Promise<void>;
        on<A extends Json[]>(
            callback: string,
            handler: (...args: A) => unknown,
        ): Disposable;
        set(props: Props): void;
        bind(props: () => Props): Disposable;
        show(): Promise<void>;
        hide(): Promise<void>;
        close(): Promise<void>;
        opened: boolean;
        onClose(listener: () => unknown): Disposable;
    }

    Hierarchy (View Summary)

    Index
    • Release the resource. Resolves once the player confirmed the release (or immediately for purely local resources). Never rejects.

      Returns Promise<void>

      Never.

      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
      });

      1.0.0

    • Handle a Slint callback.

      Type Parameters

      Parameters

      • callback: string

        The Slint callback's name, in camelCase (toggleEffect) or as written in Slint (toggle-effect).

      • handler: (...args: A) => unknown

        Receives the callback's arguments.

      Returns Disposable

      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();

      1.0.0

    • Write properties now, even values that did not change.

      Parameters

      Returns void

      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.

      Example: Put a drop-down back when the user picks an entry the plugin refuses

      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;
      });

      1.0.0

    • Keep properties equal to a function of the plugin's state.

      Parameters

      • props: () => Props

        Returns the properties, by name.

      Returns Disposable

      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());

      1.0.0

    • Open the window, or show it again if it is hidden.

      Returns Promise<void>

      Resolves once the player has shown the window.

      When no window instance exists (the first call, or after a close), the player compiles the Slint file and opens a new window. Its initial properties are the bound values and the values last passed to View.set, so no default values flash, and the callbacks bound so far are registered. When the window is hidden, it is shown again with its state.

      show, hide and close of one window run one after another in call order. After dispose(), show does nothing.

      unavailable (rejects) The player runs without a user interface.

      host (rejects) The Slint file is missing, outside the package directory or does not compile; it exports more than one component; or a bound property or callback is not declared in it. message has the reason, including the compiler's diagnostics.

      missing (rejects) An image in the initial properties does not exist (see Ui.image).

      invalid (rejects) An image in the initial properties fails another check: outside the allowed directories, too large, not PNG or JPEG.

      When the inspector cannot open, the user sees why on the OSD instead of nothing happening. show compiles the Slint file and opens the window; it rejects with a code, such as host for a Slint file that does not compile or unavailable without a user interface.

      const inspectorWindow = plugin.windows.create("ui/inspector.slint");
      try {
      await inspectorWindow.show();
      } catch (error) {
      // The code is data; `message` has the details for the log.
      await plugin.osd.show("Cannot open the inspector ({})", [(error as PluginError).code]);
      }

      1.0.0

    • Hide the window without closing it.

      Returns Promise<void>

      Resolves once the window is hidden.

      The instance and everything in it stay; Window.opened stays true and Window.show brings the window back as it was. Does nothing when the window is not open.

      missing (rejects) The user closed the window just before (the close had not reached the plugin yet).

      Audio ▸ Levels shows the window with a check mark and hides it again. hide keeps the window's instance and state, so showing it again is instant; the check mark follows visible, and onClose resets it when the user closes the window with its title-bar button.

      const levels = plugin.windows.create("ui/levels.slint");
      let visible = false; // what the check mark shows
      plugin.commands.add({
      id: "levels",
      path: ["@audio", "Levels"],
      checked: () => visible,
      run: async () => {
      visible = !visible;
      await (visible ? levels.show() : levels.hide());
      },
      });
      levels.onClose(() => (visible = false));

      1.0.0

    • Close the window and destroy its instance; the handle stays usable.

      Returns Promise<void>

      Resolves once the window is closed.

      The next Window.show opens a fresh instance with the current properties; state that only the Slint side had (text the plugin did not record) is gone. Window.onClose is not called. Does nothing when the window is not open. Unlike dispose(), the handle, its handlers and its bindings stay.

      missing (rejects) The user closed the window just before.

      The editor's Done button closes the editor window. close destroys the window instance but keeps the handle, its handlers and bindings, so the next show opens a fresh window; onClose is not called for the plugin's own close.

      const editor = plugin.windows.create("ui/editor.slint");
      editor.on("done", () => editor.close());

      1.0.0

    • Run code when the user closes the window.

      Parameters

      • listener: () => unknown

        Called with no arguments; may be async.

      Returns Disposable

      A handle that removes the listener.

      Called for the title-bar close button and the standard close keys. When it runs, the window instance is gone and Window.opened is already false; a later show() opens a fresh one. It is not called for the plugin's own Window.close or dispose(), nor when the plugin stops. Errors it throws go to Scope.onError, and an update pass follows.

      Stop what the window needed here: timers, polling, a live preview.

      The plugin records that the notes window was closed, so it does not reopen it at the next start. onClose runs for the title-bar button, the player's close keys (Cmd+W, Ctrl+W, Ctrl+F4) and the system's own close request such as Alt+F4 (not for the plugin's own close); the store writes the change to window.json shortly after.

      const store = plugin.storage.json("window", { defaults: { open: false } });
      const notesWindow = plugin.windows.create("ui/notes.slint");
      notesWindow.onClose(() => store.save({ open: false }));

      1.0.0

    opened: boolean

    Whether a window instance exists, shown or hidden: false before the first Window.show, after Window.close, after the user closed the window and after dispose().