Ask the user to confirm something.
The text and buttons; see ConfirmOptions.
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).
busy (rejects) Another dialog is open, or another
confirmation or the approval sheet is waiting for the user's answer.
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.
}
Ask the user for one file to open.
The absolute path, or null when the user cancelled.
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
Ask the user for one or more files to open.
The absolute paths, or [] when the user cancelled.
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]);
Ask the user for a folder.
The absolute path, or null when the user cancelled.
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
Ask the user where to save a file.
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?: TextValueThe dialog's title (English source text or a Text), at most 256 bytes.
OptionalfileName?: TextValueThe 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 -).
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
Confirmations and the system's open and save file dialogs.
plugin.dialogs.Remarks
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 alsobusywhile 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.
Example: Ask before deleting, remembering "Don't ask again"
Deleting asks for confirmation with a "Don't ask again" box; once the user ticks it, later deletes go ahead without asking.
confirmresolves with the button and the checkbox when the user answers; the texts are templates the player translates, so the count goes inargs. Remembering the box is up to the plugin.See
Platforms
Since
1.0.0