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

    Interface View

    The surface that tool windows, panels and settings pages share: properties out to Slint, callbacks in from Slint.

    The plugin's TypeScript and its Slint files run in different processes and exchange two kinds of messages. Plugin → UI: in and in-out properties, written with View.set or kept up to date with View.bind. UI → plugin: Slint callbacks (returning nothing), handled with View.on. A Window declares them on its exported component; a Panel and a SettingsPage declare them on the file's exported global, the bridge. The plugin cannot call Slint functions or read a property back: a value the user changes reaches it only through a callback.

    bind is the usual way: the SDK re-evaluates bound functions in every full update pass (after each handler it calls, on Scope.update), and after a player state change those that read a changed field of plugin.player.state, and sends only what changed, at most one write in flight per view. set sends now, even an unchanged value.

    Writes that fail (a name the Slint file does not declare, a value of the wrong type, an image that fails its check): a bound value is not sent again until it changes; a set value is retried with back-off (0.25 s, doubling up to 30 s); the first failure of a series is reported to Scope.onError.

    A control whose value both the user and the plugin change needs a two-way binding to an in-out property (value <=> root.level). A one-way binding (value: root.level) is broken by Slint the first time the user moves the control.

    A Bookmark window shows the saved position and two buttons that save it and jump back to it. bind keeps the label and the buttons' enabled state equal to the plugin's state: the SDK evaluates the function again after every handler and player change and sends only what changed. The buttons' Slint callbacks reach the plugin through on.

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

    ui/bookmark.slint:

    import { Button, VerticalBox, HorizontalBox } from "std-widgets.slint";
    export component BookmarkWindow inherits Window {
        title: "Bookmark";
        preferred-width: 320px;
        in property <string> label: "No bookmark";
        in property <bool> can-mark;
        in property <bool> can-jump;
        callback mark();
        callback jump();
        VerticalBox {
            Text { text: root.label; }
            HorizontalBox {
                Button { text: "Mark this position"; enabled: root.can-mark; clicked => { root.mark(); } }
                Button { text: "Jump to bookmark"; enabled: root.can-jump; clicked => { root.jump(); } }
            }
        }
    }
    

    1.0.0

    interface View {
        on<A extends Json[]>(
            callback: string,
            handler: (...args: A) => unknown,
        ): Disposable;
        set(props: Props): void;
        bind(props: () => Props): Disposable;
    }

    Hierarchy (View Summary)

    Index
    • 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