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

    Interface Dialogs

    Confirmations and the system's open and save file dialogs. plugin.dialogs.

    The plugin passes text and gets the answer. A confirmation for the main window is drawn in the player; one asked while a tool window has the focus, and every file dialog, is the system's own (see Dialogs.confirm). Each call resolves when the user answers; there is no time limit and no way to close a dialog from code. Only one system dialog (of any kind, from any plugin) is open at a time: another call meanwhile rejects with busy. A confirmation is also busy while another confirmation or the player's approval sheet waits for the user's answer; the file dialogs are not. Playback continues while a dialog is open; command key bindings pause.

    Platforms: every system with a window; a player without one (headless) rejects every call with unavailable.

    For anything more than a question or a path, use a tool.

    Deleting asks for confirmation with a "Don't ask again" box; once the user ticks it, later deletes go ahead without asking. confirm resolves with the button and the checkbox when the user answers; the texts are templates the player translates, so the count goes in args. Remembering the box is up to the plugin.

    const store = plugin.storage.json("confirm", { defaults: { askBeforeDelete: true } });
    async function deleteAll(count: number) {
    if (store.value.askBeforeDelete) {
    const { confirmed, checked } = await plugin.dialogs.confirm({
    message: "Delete {} bookmarks?",
    args: [count],
    detail: "This cannot be undone.",
    confirm: "Delete",
    destructive: true,
    checkbox: "Don't ask again",
    });
    if (!confirmed) return;
    if (checked) store.save({ askBeforeDelete: false });
    }
    // … delete …
    }

    1.0.0

    interface Dialogs {
        confirm(
            options: ConfirmOptions,
        ): Promise<{ confirmed: boolean; checked: boolean }>;
        openFile(options?: { title?: TextValue }): Promise<string | null>;
        openFiles(options?: { title?: TextValue }): Promise<string[]>;
        openDirectory(options?: { title?: TextValue }): Promise<string | null>;
        saveFile(
            options?: { title?: TextValue; fileName?: TextValue },
        ): Promise<string | null>;
    }
    Index
    • Ask the user to confirm something.

      Parameters

      Returns Promise<{ confirmed: boolean; checked: boolean }>

      The answer: confirmed is true when the user picked the confirm button (Escape, the cancel button or closing the dialog give false); checked is the checkbox's state (false without one).

      For the main window (no tool window has the focus, also while the player is not in the foreground, which then takes no focus): drawn in the player in the style of its approval sheet, the same on every system: message, then detail (a long one scrolls; the sheet stays inside the window and its buttons in view), the checkbox at the footer's left and the confirm (Enter) and cancel (Esc) buttons at its right. Presses in its first 0.5 s are ignored, and a click outside it is Cancel. A click toggles the checkbox (Space does not). destructive draws nothing different.

      For a tool window (a plugin's window, Options or the floating sidebar has the focus): the system's dialog on that window. macOS: an NSAlert sheet with the custom buttons and the checkbox. Windows: a task dialog titled "Vestra Player" and centred on the window: message is the main instruction and detail the text below it; a checkbox is the dialog's own verification box (no second dialog); no system sound plays; destructive shows a warning icon. Other systems have no system alerts, so it is drawn in the player there too.

      Either way checked is the checkbox's state on cancel too.

      Remembering "Don't ask again" is up to the plugin (see Scope.storage).

      invalid (rejects) A text is empty or too long, or destructive is not a boolean.

      busy (rejects) Another dialog is open, or another confirmation or the approval sheet is waiting for the user's answer.

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

      unsupported (rejects) Only players before the confirmation drawn in the player, on a system other than macOS and Windows.

      The user sees "Replace the current playlist?" with a Replace button and the playlist is replaced only after a yes. The promise resolves when the user answers; only one dialog waits for the user at a time, so a second one meanwhile rejects with busy.

      try {
      const { confirmed } = await plugin.dialogs.confirm({
      message: "Replace the current playlist?",
      confirm: "Replace",
      });
      if (confirmed) await plugin.osd.show("Playlist replaced");
      } catch (error) {
      if ((error as PluginError).code !== "busy") throw error;
      // Another dialog is waiting: let the user finish that one.
      }

      1.0.0

    • Ask the user for one file to open.

      Parameters

      • Optionaloptions: { title?: TextValue }

        title: the dialog's title, at most 256 bytes.

        • Optionaltitle?: TextValue

          The dialog's title (English source text or a Text), at most 256 bytes.

      Returns Promise<string | null>

      The absolute path, or null when the user cancelled.

      busy (rejects) Another dialog is open.

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

      invalid (rejects) title is longer than 256 bytes.

      The system's Open dialog appears titled "Choose a subtitle file" and the chosen path is shown on the OSD. The promise resolves when the user answers: with the absolute path, or null when they cancelled.

      const path = await plugin.dialogs.openFile({ title: "Choose a subtitle file" });
      if (path !== null) await plugin.osd.show("Chosen: {}", [path]); // a path is data

      1.0.0

    • Ask the user for one or more files to open.

      Parameters

      • Optionaloptions: { title?: TextValue }

        title: the dialog's title, at most 256 bytes.

        • Optionaltitle?: TextValue

          The dialog's title (English source text or a Text), at most 256 bytes.

      Returns Promise<string[]>

      The absolute paths, or [] when the user cancelled.

      busy (rejects) Another dialog is open.

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

      invalid (rejects) title is longer than 256 bytes.

      The Open dialog allows selecting several files; the OSD says how many were added. The promise resolves with the absolute paths, or with an empty array when the user cancelled.

      const paths = await plugin.dialogs.openFiles({ title: "Add to the playlist" });
      if (paths.length) await plugin.osd.show("{} files added", [paths.length]);

      1.0.0

    • Ask the user for a folder.

      Parameters

      • Optionaloptions: { title?: TextValue }

        title: the dialog's title, at most 256 bytes.

        • Optionaltitle?: TextValue

          The dialog's title (English source text or a Text), at most 256 bytes.

      Returns Promise<string | null>

      The absolute path, or null when the user cancelled.

      busy (rejects) Another dialog is open.

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

      invalid (rejects) title is longer than 256 bytes.

      The system's folder dialog appears titled "Save snapshots in". It resolves with the folder's absolute path, or null when the user cancelled, in which case the plugin stops there.

      const folder = await plugin.dialogs.openDirectory({ title: "Save snapshots in" });
      if (folder === null) return; // cancelled

      1.0.0

    • Ask the user where to save a file.

      Parameters

      • Optionaloptions: { title?: TextValue; fileName?: TextValue }

        title: the dialog's title, at most 256 bytes. fileName: the proposed file name (a plain name without / or \, at most 256 bytes). @returns The absolute path, or null when the user cancelled.

        • Optionaltitle?: TextValue

          The dialog's title (English source text or a Text), at most 256 bytes.

        • OptionalfileName?: TextValue

          The proposed file name: a plain name, at most 256 bytes. A string is data (not translated); a Text is shown translated, text("Playlist.m3u8") (a / or \\ in a translation becomes -).

      Returns Promise<string | null>

      The dialog only returns a path; writing the file is up to the plugin.

      busy (rejects) Another dialog is open.

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

      invalid (rejects) title is too long, or fileName is too long or contains / or ``.

      The system's Save dialog proposes "frame.png" and returns where the user wants it. The dialog only returns the path (or null when cancelled); writing the file is up to the plugin afterwards.

      const path = await plugin.dialogs.saveFile({ title: "Save snapshot", fileName: "frame.png" });
      if (path === null) return; // cancelled

      1.0.0