@vestra-player/sdk 1.7.8 → 1.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/api-requests.js +3 -0
- package/dist/capabilities.d.ts +9 -0
- package/dist/capabilities.js +1 -0
- package/dist/capability-rules.d.ts +3 -0
- package/dist/capability-rules.js +6 -1
- package/dist/commands.d.ts +15 -2
- package/dist/commands.js +7 -1
- package/dist/docs-tree.json.gz +0 -0
- package/dist/host-capabilities.js +53 -0
- package/dist/manifest.js +12 -1
- package/dist/player-runtime.d.ts +1 -0
- package/dist/player-runtime.js +1 -0
- package/dist/plugin/commands.d.ts +2 -1
- package/dist/plugin/commands.js +131 -4
- package/dist/plugin/connection.d.ts +7 -1
- package/dist/plugin/connection.js +16 -3
- package/dist/plugin/errors.d.ts +5 -1
- package/dist/plugin/errors.js +8 -2
- package/dist/plugin/index.js +4 -0
- package/dist/plugin/player.js +1 -1
- package/dist/plugin/scope.d.ts +1 -0
- package/dist/plugin/scope.js +2 -1
- package/dist/plugin/subtitles.js +2 -2
- package/dist/plugin/testing/commands.d.ts +7 -0
- package/dist/plugin/testing/commands.js +211 -0
- package/dist/plugin/testing/index.d.ts +70 -0
- package/dist/plugin/testing/index.js +66 -1
- package/dist/plugin/testing/internals.d.ts +14 -0
- package/dist/plugin/testing/internals.js +14 -1
- package/dist/plugin/types/base.d.ts +8 -5
- package/dist/plugin/types/commands.d.ts +412 -1
- package/dist/request-queue.d.ts +66 -0
- package/dist/request-queue.js +209 -0
- package/dist/source.d.ts +2 -1
- package/dist/source.js +3 -5
- package/dist/subtitles.d.ts +4 -2
- package/dist/subtitles.js +4 -10
- package/dist/wire.d.ts +25 -4
- package/dist/wire.js +6 -0
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/slint/vestra/icons.slint +4 -0
|
@@ -85,7 +85,7 @@ import { PATCH_FEATURE } from "../patch.js";
|
|
|
85
85
|
import { LOCALES, LIST_SEPARATORS, loadPackageCatalog, TEXT_LIMITS, } from "../../i18n.js";
|
|
86
86
|
import { Internals } from "./internals.js";
|
|
87
87
|
import { on, emit, settle, close, keepsRunning, transportHandlers, tick, takenErrors, tellResidency, } from "./transport.js";
|
|
88
|
-
import { bindingClaims, bindingKey, keysChanged, press, barButtons, commandsHandlers, } from "./commands.js";
|
|
88
|
+
import { bindingClaims, bindingKey, keysChanged, press, barButtons, commandsHandlers, builtinHandlers, runPaletteLead, } from "./commands.js";
|
|
89
89
|
import { registerCoreActions, windowFacts, coreActionsHandlers, } from "./core-actions.js";
|
|
90
90
|
import { translate, i18nHandlers } from "./i18n.js";
|
|
91
91
|
import { mountOther, unmountOther, mounted, setTimelineRanges, setTimelineLayer, layoutHandlers, } from "./layout.js";
|
|
@@ -1828,6 +1828,68 @@ export class TestHost {
|
|
|
1828
1828
|
steps = [];
|
|
1829
1829
|
/** Every core action run (`host.run`, a core command, a pressed core binding), newest last. */
|
|
1830
1830
|
coreRuns = [];
|
|
1831
|
+
// ------------------------------------------------------------ built-in only
|
|
1832
|
+
/**
|
|
1833
|
+
* The plugin is built into the player (`startPlugin`'s `builtin`). Only
|
|
1834
|
+
* then does the host take the built-in-only capabilities
|
|
1835
|
+
* (`commands.run`, `palette.lead`); otherwise their calls fail with
|
|
1836
|
+
* `capability`, as in the player.
|
|
1837
|
+
*
|
|
1838
|
+
* @since 1.7.9
|
|
1839
|
+
*/
|
|
1840
|
+
builtin = false;
|
|
1841
|
+
/**
|
|
1842
|
+
* The palette's lead row as the plugin last set it (`palette.lead.set`,
|
|
1843
|
+
* wire form), `null` without one. Wire-level.
|
|
1844
|
+
*
|
|
1845
|
+
* @since 1.7.9
|
|
1846
|
+
*/
|
|
1847
|
+
paletteLead = null;
|
|
1848
|
+
/**
|
|
1849
|
+
* Simulate the user activating the palette's lead row: Enter (`keep`:
|
|
1850
|
+
* Shift+Enter) with `query` typed, or Enter on the status row
|
|
1851
|
+
* (`status`). Mints a ticket, sends the `palette.lead` event, waits until
|
|
1852
|
+
* the host is idle and returns the ticket.
|
|
1853
|
+
*
|
|
1854
|
+
* Like the player, `commands.run` takes the ticket until
|
|
1855
|
+
* `PaletteLead.done` or 120 s after its last run, at most 30 runs, 4 a
|
|
1856
|
+
* second, and 120 runs a minute per plugin (`limit`). A command declared
|
|
1857
|
+
* `destructive` (and the player's `host/stop`) is confirmed first: the
|
|
1858
|
+
* answer comes from {@link TestHost.dialogAnswers}
|
|
1859
|
+
* (`{ confirmed: false, checked: false }` is Don't Run); each run adds
|
|
1860
|
+
* the command's title (and ` · step/of`) to {@link TestHost.osd}.
|
|
1861
|
+
*
|
|
1862
|
+
* @param query - What the user typed.
|
|
1863
|
+
* @param options - `keep`: Shift+Enter; `status`: the status row.
|
|
1864
|
+
* @returns The ticket of this user action.
|
|
1865
|
+
*
|
|
1866
|
+
* @example Test a request that runs a destructive command
|
|
1867
|
+
* The user asks the plugin to stop playback and declines the
|
|
1868
|
+
* confirmation. `builtin` lets the plugin hold the lead; the ticket
|
|
1869
|
+
* minted here is what its listener passes to `commands.run`, and the
|
|
1870
|
+
* queued answer declines the player's alert for `host/stop`.
|
|
1871
|
+
* ```ts
|
|
1872
|
+
* import assert from "node:assert/strict";
|
|
1873
|
+
* import { startPlugin } from "@vestra-player/sdk/testing";
|
|
1874
|
+
* import activate from "../main.ts";
|
|
1875
|
+
*
|
|
1876
|
+
* const { host, stop } = await startPlugin(activate, {
|
|
1877
|
+
* directory: new URL("..", import.meta.url),
|
|
1878
|
+
* builtin: true, // as a plugin built into the player
|
|
1879
|
+
* });
|
|
1880
|
+
* host.dialogAnswers.push({ confirmed: false, checked: false }); // Don't Run
|
|
1881
|
+
* await host.runPaletteLead("stop playback");
|
|
1882
|
+
* assert.deepEqual(host.coreRuns, []); // declined: nothing ran
|
|
1883
|
+
* await stop();
|
|
1884
|
+
* ```
|
|
1885
|
+
*
|
|
1886
|
+
* @capability None.
|
|
1887
|
+
* @throws `Error` without a code (rejects) The plugin has no lead row.
|
|
1888
|
+
* @since 1.7.9
|
|
1889
|
+
*/
|
|
1890
|
+
runPaletteLead(query, options = {}) {
|
|
1891
|
+
return runPaletteLead(this, this.#inner, query, options);
|
|
1892
|
+
}
|
|
1831
1893
|
/**
|
|
1832
1894
|
* One of the 14 core actions (`play-pause`, `stop`, `seek-forward`, ...)
|
|
1833
1895
|
* that the test host registers like the player, as `host/<id>`. Throws for
|
|
@@ -2667,6 +2729,7 @@ export class TestHost {
|
|
|
2667
2729
|
#defaults = {
|
|
2668
2730
|
...transportHandlers(this, this.#inner),
|
|
2669
2731
|
...commandsHandlers(this, this.#inner),
|
|
2732
|
+
...builtinHandlers(this, this.#inner),
|
|
2670
2733
|
...coreActionsHandlers(this, this.#inner),
|
|
2671
2734
|
...i18nHandlers(this, this.#inner),
|
|
2672
2735
|
...layoutHandlers(this, this.#inner),
|
|
@@ -2777,6 +2840,8 @@ export async function startPlugin(activate, options = {}) {
|
|
|
2777
2840
|
manifest = { id: read.id, capabilities: read.capabilities };
|
|
2778
2841
|
}
|
|
2779
2842
|
host.manifestId = manifest.id;
|
|
2843
|
+
if (options.builtin)
|
|
2844
|
+
host.builtin = true;
|
|
2780
2845
|
host.loadCatalog(directory);
|
|
2781
2846
|
// Its Slint files: the values its views are given are checked against
|
|
2782
2847
|
// their declared types.
|
|
@@ -70,7 +70,21 @@ export declare class Internals {
|
|
|
70
70
|
producer: number;
|
|
71
71
|
source: number;
|
|
72
72
|
resolution: number;
|
|
73
|
+
ticket: number;
|
|
73
74
|
};
|
|
75
|
+
/** `commands.run` tickets: runs, run times in the last second, last use (ms). */
|
|
76
|
+
readonly tickets: Map<string, {
|
|
77
|
+
count: number;
|
|
78
|
+
runs: number[];
|
|
79
|
+
last: number;
|
|
80
|
+
}>;
|
|
81
|
+
/** The last `commands.list` table (JSON) and its revision. */
|
|
82
|
+
listed: {
|
|
83
|
+
text: string;
|
|
84
|
+
revision: number;
|
|
85
|
+
};
|
|
86
|
+
/** The times of the plugin's `commands.run` calls in the last minute. */
|
|
87
|
+
runs: number[];
|
|
74
88
|
sourceBook: Map<number, Json>;
|
|
75
89
|
/** The pending resolutions' stamps and operations (beside `resolutions`). */
|
|
76
90
|
resolving: Map<number, {
|
|
@@ -47,7 +47,20 @@ export class Internals {
|
|
|
47
47
|
gone.catch(() => { });
|
|
48
48
|
return gone;
|
|
49
49
|
})();
|
|
50
|
-
next = {
|
|
50
|
+
next = {
|
|
51
|
+
snapshot: 0,
|
|
52
|
+
job: 0,
|
|
53
|
+
producer: 0,
|
|
54
|
+
source: 0,
|
|
55
|
+
resolution: 0,
|
|
56
|
+
ticket: 0,
|
|
57
|
+
};
|
|
58
|
+
/** `commands.run` tickets: runs, run times in the last second, last use (ms). */
|
|
59
|
+
tickets = new Map();
|
|
60
|
+
/** The last `commands.list` table (JSON) and its revision. */
|
|
61
|
+
listed = { text: "", revision: 0 };
|
|
62
|
+
/** The times of the plugin's `commands.run` calls in the last minute. */
|
|
63
|
+
runs = [];
|
|
51
64
|
sourceBook = new Map();
|
|
52
65
|
/** The pending resolutions' stamps and operations (beside `resolutions`). */
|
|
53
66
|
resolving = new Map();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Command, CommandOptions } from "./commands.ts";
|
|
1
|
+
import type { Command, CommandOptions, PaletteLeadRun } from "./commands.ts";
|
|
2
2
|
import type { PackageCandidate, PluginInfo } from "./packages.ts";
|
|
3
3
|
import type { Conditional, Media, Stream } from "./playback.ts";
|
|
4
4
|
import type {
|
|
@@ -10,7 +10,7 @@ import type { ExportJob, MediaSources, Snapshot } from "./snapshots.ts";
|
|
|
10
10
|
import type { Resolver } from "./sources.ts";
|
|
11
11
|
import type { PropValue, View } from "./ui-content.ts";
|
|
12
12
|
import type { Panel, Window } from "./ui-layout.ts";
|
|
13
|
-
import type { Bindings, Commands, Host, When } from "./commands.ts";
|
|
13
|
+
import type { Bindings, Commands, Host, Palette, When } from "./commands.ts";
|
|
14
14
|
import type { Packages } from "./packages.ts";
|
|
15
15
|
import type { Player, Timeline } from "./playback.ts";
|
|
16
16
|
import type { AudioFilter, RenderOptions, VideoFilter, VideoShaders, VideoUpscaling, VideoView } from "./processing.ts";
|
|
@@ -100,7 +100,7 @@ export interface Disposable {
|
|
|
100
100
|
* | `invalid` | A bad argument (out of range, malformed, unknown id). |
|
|
101
101
|
* | `missing` | The target does not exist (an empty panel position, a missing file, an unknown command). |
|
|
102
102
|
* | `busy` | The player is still doing a previous call of the same kind (a dialog is open, a step is in flight). |
|
|
103
|
-
* | `conflict` | Another plugin owns the resource (the sequence provider, the display layer, the backdrop, a menu path), or this plugin already uses the id (a window or command id). |
|
|
103
|
+
* | `conflict` | Another plugin owns the resource (the sequence provider, the display layer, the backdrop, a menu path, the command palette's lead row), or this plugin already uses the id (a window or command id). |
|
|
104
104
|
* | `unavailable` | Not possible right now (no ready media, no user interface, fullscreen, a disabled core action). |
|
|
105
105
|
* | `unsupported` | Not possible on this system, build or source (a platform gap, software rendering, a source that cannot seek, a filter on a generated stream, an export the player cannot make as asked: a stream copy, a source bitrate it cannot tell). |
|
|
106
106
|
* | `backend` | Loading or resolving failed; `message` is the backend's reason. |
|
|
@@ -113,13 +113,14 @@ export interface Disposable {
|
|
|
113
113
|
* | `timeout` | A time limit ran out (`openStream` start-up, `tools.run`, `system.*` after 10 s). |
|
|
114
114
|
* | `stream`, `device` | `openStream`: the producer failed / the audio device is not ready. |
|
|
115
115
|
* | `backend-uncertain` | The player's backend blocked a filter stage; call `retry()`. |
|
|
116
|
-
* | `limit` | A player-wide limit was reached (for example the number of commands), a property value is over the limits of {@link PropValue},
|
|
116
|
+
* | `limit` | A player-wide limit was reached (for example the number of commands), a property value is over the limits of {@link PropValue}, a request is longer than the player's 1 MiB message, {@link Commands.run} ran too often, or a client that bypasses the SDK left more than 320 requests or 4 MiB of them unanswered (the player's backstop; the SDK keeps a plugin under it). |
|
|
117
117
|
* | `reserved` | {@link Packages.validate}, {@link PackageCandidate.install}: the id is `vestra` or starts with `vestra.` (any case), which only the player's built-in plugins use. |
|
|
118
118
|
* | `versionMismatch` | The package needs a newer player (`minPlayerVersion`). |
|
|
119
119
|
* | `ui-prepare` | The player could not prepare a mounted panel or a settings page (its Slint file does not compile, a bound property is not declared, or another plugin's panel holds the slot); `message` has the diagnostics. |
|
|
120
120
|
* | `ui` | The player could not apply a property to a tool window or a settings page, or could not build the Options window (a property the Slint file does not declare, a value of the wrong type); `message` has Slint's reason. Also reported to {@link Scope.onError} without a request: a callback whose arguments the player could not convert, a property it could not show again when it rebuilt a view (an image file removed since). |
|
|
121
121
|
* | `host` | Any other failure inside the player; `message` is the player's reason. |
|
|
122
|
-
* | `disabled` | The plugin is being stopped; pending requests fail with it. |
|
|
122
|
+
* | `disabled` | The plugin is being stopped; pending requests fail with it. {@link Commands.run}: the command is disabled; `message` has its reason. |
|
|
123
|
+
* | `ticket` | {@link Commands.run}: no ticket, or it ended or expired (a ticket comes with {@link PaletteLeadRun}). |
|
|
123
124
|
* | `unknown`, `rejected`, `expired` | After a transport problem the SDK could not confirm the outcome (does not happen in normal operation). |
|
|
124
125
|
* | `activation` | The plugin opened a tool window while its activation was still pending and the player could not track it. |
|
|
125
126
|
* | `command` | The player could not run or update a command it no longer knows for this plugin (removed meanwhile, or another plugin's). |
|
|
@@ -317,6 +318,8 @@ export interface Scope extends Disposable {
|
|
|
317
318
|
readonly packages: Packages;
|
|
318
319
|
/** On-screen messages over the video (`ui.osd`). */
|
|
319
320
|
readonly osd: Osd;
|
|
321
|
+
/** The command palette's lead row (`palette.lead`, built-in plugins only). */
|
|
322
|
+
readonly palette: Palette;
|
|
320
323
|
/** The player's own core playback actions (`commands`). */
|
|
321
324
|
readonly host: Host;
|
|
322
325
|
/** The system clipboard (`clipboard`). */
|
|
@@ -284,7 +284,7 @@ export type MenuId = "open" | "playback" | "subtitles" | "video" | "audio" | "sc
|
|
|
284
284
|
*
|
|
285
285
|
* @category Commands
|
|
286
286
|
*/
|
|
287
|
-
export type BarButtonIcon = "play" | "pause" | "stop" | "back" | "forward" | "open" | "volume" | "mute" | "playlist" | "detach" | "attach" | "close" | "failed" | "move-top" | "move-up" | "move-down" | "move-bottom" | "search" | "chapter" | "bookmark" | "check-task" | "check-box" | "menu-check" | "submenu" | "scroll-up" | "scroll-down" | "caret-down" | "sort-asc" | "sort-desc" | "tag-remove" | "preview-play" | "add" | "remove" | "sort" | "fullscreen" | "exit-fullscreen" | "store" | "ai";
|
|
287
|
+
export type BarButtonIcon = "play" | "pause" | "stop" | "back" | "forward" | "open" | "volume" | "mute" | "playlist" | "detach" | "attach" | "close" | "failed" | "move-top" | "move-up" | "move-down" | "move-bottom" | "search" | "chapter" | "bookmark" | "check-task" | "check-box" | "menu-check" | "submenu" | "scroll-up" | "scroll-down" | "caret-down" | "sort-asc" | "sort-desc" | "tag-remove" | "preview-play" | "add" | "remove" | "sort" | "fullscreen" | "exit-fullscreen" | "store" | "ai" | "sliders" | "search-ai";
|
|
288
288
|
/**
|
|
289
289
|
* A command's button on the bottom bar: {@link CommandOptions.button}.
|
|
290
290
|
*
|
|
@@ -563,6 +563,16 @@ export interface CommandOptions {
|
|
|
563
563
|
* 0–999 or a button without a path.
|
|
564
564
|
*/
|
|
565
565
|
button?: CommandButton;
|
|
566
|
+
/**
|
|
567
|
+
* The command cannot be undone: it deletes or clears the user's data,
|
|
568
|
+
* closes what is open or quits (default false). When another plugin runs
|
|
569
|
+
* it through {@link Commands.run}, the player asks the user first; a menu
|
|
570
|
+
* pick, a key or the command palette runs it as before.
|
|
571
|
+
*
|
|
572
|
+
* @player 0.7.6
|
|
573
|
+
* @since 1.7.9
|
|
574
|
+
*/
|
|
575
|
+
destructive?: boolean;
|
|
566
576
|
/**
|
|
567
577
|
* Whether the command can run (default true): a value, a function, or a
|
|
568
578
|
* {@link Condition} the player evaluates (`plugin.when`).
|
|
@@ -831,6 +841,407 @@ export interface Commands {
|
|
|
831
841
|
* @since 1.6.6
|
|
832
842
|
*/
|
|
833
843
|
keys(id: string): readonly string[];
|
|
844
|
+
/**
|
|
845
|
+
* List every command the command palette lists, the player's own and
|
|
846
|
+
* every plugin's, with its state now. **Built-in plugins only.**
|
|
847
|
+
*
|
|
848
|
+
* @remarks
|
|
849
|
+
* The palette's table as data: for a plugin that runs commands for the
|
|
850
|
+
* user (an assistant, a macro recorder, a remote control) or shows how to
|
|
851
|
+
* reach them (a tutorial that says which key opens a window). `revision`
|
|
852
|
+
* changes whenever a command is added, removed or changes state, so a copy
|
|
853
|
+
* with the same revision is still current.
|
|
854
|
+
*
|
|
855
|
+
* @example Find the key that opens a window
|
|
856
|
+
* A tutorial panel tells the user which key opens Subtitle Tuning. `list`
|
|
857
|
+
* returns the palette's rows with their places and current keys; the
|
|
858
|
+
* panel picks the row by its global id and shows its first key.
|
|
859
|
+
* ```ts
|
|
860
|
+
* try {
|
|
861
|
+
* const { commands } = await plugin.commands.list();
|
|
862
|
+
* const row = commands.find((each) => each.id === "vestra.subtitles/tuning");
|
|
863
|
+
* if (row?.keys[0]) await plugin.osd.show("Press {}", [row.keys[0]]);
|
|
864
|
+
* } catch (error) {
|
|
865
|
+
* // `capability`: not a built-in plugin, or `commands.run` not declared.
|
|
866
|
+
* if ((error as PluginError).code !== "capability") throw error;
|
|
867
|
+
* }
|
|
868
|
+
* ```
|
|
869
|
+
*
|
|
870
|
+
* @capability commands.run (built-in plugins only)
|
|
871
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
872
|
+
* `commands.run`, or the plugin is not built into the player.
|
|
873
|
+
* @player 0.7.6
|
|
874
|
+
* @since 1.7.9
|
|
875
|
+
*/
|
|
876
|
+
list(): Promise<CommandList>;
|
|
877
|
+
/**
|
|
878
|
+
* Run any command the palette lists, as the palette runs it, for a request
|
|
879
|
+
* the user made. **Built-in plugins only.**
|
|
880
|
+
*
|
|
881
|
+
* @remarks
|
|
882
|
+
* Every run needs a ticket: the player mints one only for a user action
|
|
883
|
+
* ({@link PaletteLeadRun.ticket}, Enter on the palette's lead row), so a
|
|
884
|
+
* plugin cannot run commands on its own. The ticket ends with
|
|
885
|
+
* {@link PaletteLead.done}, with the plugin's next lead run, when the
|
|
886
|
+
* plugin stops, or 120 s after it was given or last used. The player
|
|
887
|
+
* applies the palette's checks (enabled, not busy), shows an on-screen
|
|
888
|
+
* line naming the plugin and the command (`Vestra Player AI · 1/2 ·
|
|
889
|
+
* Playback: Mute`), and asks the user first (Run / Don't Run) before a
|
|
890
|
+
* command declared {@link CommandOptions.destructive}, the player's Close
|
|
891
|
+
* and Quit, anything in the Settings and Plugins menus, and every command
|
|
892
|
+
* of a plugin that is not built in. Runs are limited to 4 a second and 30
|
|
893
|
+
* per ticket, and 120 a minute per plugin. The run is not added to the
|
|
894
|
+
* palette's recent list.
|
|
895
|
+
*
|
|
896
|
+
* @param id - The command's global id, as {@link CommandInfo.id}:
|
|
897
|
+
* `<manifest id>/<local id>`, `host/<id>` for the player's own.
|
|
898
|
+
* @param options - `ticket`: from the user action this run is for.
|
|
899
|
+
* `step` and `of`: this is step `step` of `of` (1-based), shown in the
|
|
900
|
+
* on-screen line.
|
|
901
|
+
* @returns `{ ran: true }` once the command was started, or
|
|
902
|
+
* `{ ran: false, declined: true }` when the user chose Don't Run.
|
|
903
|
+
*
|
|
904
|
+
* @example Run the commands of one request
|
|
905
|
+
* The user typed "fullscreen and mute" into the palette's lead row; the
|
|
906
|
+
* plugin runs the two commands it chose for it. The ticket comes with the
|
|
907
|
+
* lead's run event and covers every run of this request; `done` ends it.
|
|
908
|
+
* A declined confirmation or a failure stops the request.
|
|
909
|
+
* ```ts
|
|
910
|
+
* declare const lead: PaletteLead;
|
|
911
|
+
* // ---cut---
|
|
912
|
+
* lead.onRun(async ({ ticket }) => {
|
|
913
|
+
* const ids = ["host/fullscreen", "host/mute"]; // chosen for the request
|
|
914
|
+
* try {
|
|
915
|
+
* for (const [index, id] of ids.entries()) {
|
|
916
|
+
* const result = await plugin.commands.run(id, { ticket, step: index + 1, of: ids.length });
|
|
917
|
+
* if (!result.ran) break; // the user chose Don't Run
|
|
918
|
+
* }
|
|
919
|
+
* } catch (error) {
|
|
920
|
+
* // `disabled`, `busy`, `missing`, `ticket` (expired), `limit` (rate).
|
|
921
|
+
* await plugin.osd.show("Stopped: {}", [(error as PluginError).message]);
|
|
922
|
+
* } finally {
|
|
923
|
+
* await lead.done(ticket);
|
|
924
|
+
* }
|
|
925
|
+
* });
|
|
926
|
+
* ```
|
|
927
|
+
*
|
|
928
|
+
* @capability commands.run (built-in plugins only)
|
|
929
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
930
|
+
* `commands.run`, or the plugin is not built into the player.
|
|
931
|
+
* @throws `ticket` (rejects) No ticket, or it ended or expired.
|
|
932
|
+
* @throws `missing` (rejects) No command has this id.
|
|
933
|
+
* @throws `disabled` (rejects) The command is disabled now; `message` has
|
|
934
|
+
* its reason.
|
|
935
|
+
* @throws `busy` (rejects) The command is busy, or its confirmation
|
|
936
|
+
* cannot be shown while another alert is open.
|
|
937
|
+
* @throws `limit` (rejects) Over the rate limits above.
|
|
938
|
+
* @throws `invalid` (rejects) Only one of `step` and `of`, or not
|
|
939
|
+
* whole numbers with 1 ≤ `step` ≤ `of` ≤ 99; or `id` is the command
|
|
940
|
+
* palette itself (`host/palette`).
|
|
941
|
+
* @player 0.7.6
|
|
942
|
+
* @since 1.7.9
|
|
943
|
+
*/
|
|
944
|
+
run(id: string, options: CommandRunOptions): Promise<CommandRunResult>;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* How {@link Commands.run} runs a command.
|
|
948
|
+
*
|
|
949
|
+
* @since 1.7.9
|
|
950
|
+
* @category Commands
|
|
951
|
+
*/
|
|
952
|
+
export interface CommandRunOptions {
|
|
953
|
+
/** The ticket of the user action the run is for ({@link PaletteLeadRun.ticket}). */
|
|
954
|
+
ticket: string;
|
|
955
|
+
/** This run's step number (1–99), for the on-screen line; with `of`. */
|
|
956
|
+
step?: number;
|
|
957
|
+
/** The request's number of steps (`step`–99); with `step`. */
|
|
958
|
+
of?: number;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* The outcome of {@link Commands.run}: the command started, or the user
|
|
962
|
+
* declined the confirmation.
|
|
963
|
+
*
|
|
964
|
+
* @since 1.7.9
|
|
965
|
+
* @category Commands
|
|
966
|
+
*/
|
|
967
|
+
export type CommandRunResult = {
|
|
968
|
+
/** The command was started. */
|
|
969
|
+
ran: true;
|
|
970
|
+
} | {
|
|
971
|
+
/** The command was not started. */
|
|
972
|
+
ran: false;
|
|
973
|
+
/** The user chose Don't Run in the confirmation. */
|
|
974
|
+
declined: true;
|
|
975
|
+
};
|
|
976
|
+
/**
|
|
977
|
+
* The command palette's table, from {@link Commands.list}.
|
|
978
|
+
*
|
|
979
|
+
* @since 1.7.9
|
|
980
|
+
* @category Commands
|
|
981
|
+
*/
|
|
982
|
+
export interface CommandList {
|
|
983
|
+
/** The table's revision: the same number means the same table. */
|
|
984
|
+
revision: number;
|
|
985
|
+
/**
|
|
986
|
+
* Every command the palette lists, in no particular order: not a
|
|
987
|
+
* panel-only command, nor a disabled one without a reason.
|
|
988
|
+
*/
|
|
989
|
+
commands: CommandInfo[];
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* One command of the palette's table ({@link CommandList}), with its texts
|
|
993
|
+
* as the palette shows them in the interface language.
|
|
994
|
+
*
|
|
995
|
+
* @since 1.7.9
|
|
996
|
+
* @category Commands
|
|
997
|
+
*/
|
|
998
|
+
export interface CommandInfo {
|
|
999
|
+
/** The global id: `<manifest id>/<local id>`, `host/<id>` for the player's own. */
|
|
1000
|
+
id: string;
|
|
1001
|
+
/** The row's text, `Category: Title`, as shown. */
|
|
1002
|
+
label: string;
|
|
1003
|
+
/** The same in English source text. */
|
|
1004
|
+
labelSource: string;
|
|
1005
|
+
/** The command's title as shown. */
|
|
1006
|
+
title: string;
|
|
1007
|
+
/**
|
|
1008
|
+
* The row's category as shown: the declared category, else the menu path
|
|
1009
|
+
* above the command (`Video ▸ Snapshot`), else the plugin's name.
|
|
1010
|
+
*/
|
|
1011
|
+
category: string;
|
|
1012
|
+
/** Its menu path as shown, empty for a command outside the menus. */
|
|
1013
|
+
path: string[];
|
|
1014
|
+
/**
|
|
1015
|
+
* Where it lives: the window its `home` command opens, `Menu`, the menu
|
|
1016
|
+
* above it (`Video ▸`), or `""` outside the menus.
|
|
1017
|
+
*/
|
|
1018
|
+
place: string;
|
|
1019
|
+
/** Its current keys as the menus write them. */
|
|
1020
|
+
keys: string[];
|
|
1021
|
+
/** The owning plugin's name as shown, `Vestra Player` for the player's own. */
|
|
1022
|
+
plugin: string;
|
|
1023
|
+
/** The owner is the player or a built-in plugin. */
|
|
1024
|
+
builtin: boolean;
|
|
1025
|
+
/** It can run now. */
|
|
1026
|
+
enabled: boolean;
|
|
1027
|
+
/** Why it is disabled, as shown (only while disabled). */
|
|
1028
|
+
reason?: string;
|
|
1029
|
+
/** It has a check mark or a radio dot. */
|
|
1030
|
+
checkable: boolean;
|
|
1031
|
+
/** The check mark now (with `checkable`). */
|
|
1032
|
+
checked?: boolean;
|
|
1033
|
+
/** The mark is a radio dot. */
|
|
1034
|
+
radio: boolean;
|
|
1035
|
+
/** Its separator group in the menu. */
|
|
1036
|
+
group: string;
|
|
1037
|
+
/** It is busy now. */
|
|
1038
|
+
busy: boolean;
|
|
1039
|
+
/** {@link Commands.run} asks the user before running it. */
|
|
1040
|
+
dangerous: boolean;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* `plugin.palette`: the command palette's lead row.
|
|
1044
|
+
*
|
|
1045
|
+
* @remarks
|
|
1046
|
+
* The palette's first row hands what the user typed to a plugin: a
|
|
1047
|
+
* calculator ("3.5 GB in MB"), a library or history search, jump to a time,
|
|
1048
|
+
* an assistant that runs commands for a sentence. There is one lead in the
|
|
1049
|
+
* player, and only a built-in plugin can hold it.
|
|
1050
|
+
*
|
|
1051
|
+
* @capability palette.lead (built-in plugins only)
|
|
1052
|
+
*
|
|
1053
|
+
* @example Answer typed time stamps from the palette
|
|
1054
|
+
* The palette's first row reads "Go to: 12:30"; Enter seeks there. `lead`
|
|
1055
|
+
* puts the row up; the player sends the typed text with Enter, and the
|
|
1056
|
+
* plugin ends the request with `done`.
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* // Put up the row once, in activate: the player keeps it while stopped.
|
|
1059
|
+
* const lead = plugin.palette.lead({ title: "Go to", icon: "search" });
|
|
1060
|
+
* lead.onRun(async ({ query, ticket }) => {
|
|
1061
|
+
* const [minutes = 0, seconds = 0] = query.split(":").map(Number); // "12:30"
|
|
1062
|
+
* await plugin.player.seek(minutes * 60 + seconds);
|
|
1063
|
+
* await lead.done(ticket); // this request needs no command runs
|
|
1064
|
+
* });
|
|
1065
|
+
* ```
|
|
1066
|
+
*
|
|
1067
|
+
* @player 0.7.6
|
|
1068
|
+
* @since 1.7.9
|
|
1069
|
+
* @category Commands
|
|
1070
|
+
*/
|
|
1071
|
+
export interface Palette {
|
|
1072
|
+
/**
|
|
1073
|
+
* Put up the palette's lead row. **Built-in plugins only.**
|
|
1074
|
+
*
|
|
1075
|
+
* The player keeps the row while the plugin is stopped and starts the
|
|
1076
|
+
* plugin for a run, so call it in `activate`. Disposing the handle (or
|
|
1077
|
+
* its scope) removes the row.
|
|
1078
|
+
*
|
|
1079
|
+
* @example See Palette
|
|
1080
|
+
* {@link Palette}
|
|
1081
|
+
*
|
|
1082
|
+
* @capability palette.lead (built-in plugins only)
|
|
1083
|
+
* @throws `capability` (through `ready`) The manifest does not declare
|
|
1084
|
+
* `palette.lead`, or the plugin is not built into the player.
|
|
1085
|
+
* @throws `conflict` (through `ready`) Another plugin holds the lead.
|
|
1086
|
+
* @throws `invalid` (through `ready`) A text over its length.
|
|
1087
|
+
* @player 0.7.6
|
|
1088
|
+
* @since 1.7.9
|
|
1089
|
+
*/
|
|
1090
|
+
lead(options: PaletteLeadOptions): PaletteLead;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* What the palette's lead row shows ({@link Palette.lead}). Texts are
|
|
1094
|
+
* English source text or a {@link Text}, translated like command titles.
|
|
1095
|
+
*
|
|
1096
|
+
* @since 1.7.9
|
|
1097
|
+
* @category Commands
|
|
1098
|
+
*/
|
|
1099
|
+
export interface PaletteLeadOptions {
|
|
1100
|
+
/** The row reads `title: <typed text>`, or `title` alone with nothing typed (1–40 characters). */
|
|
1101
|
+
title: string | Text;
|
|
1102
|
+
/** A name of the player's icon set ({@link BarButtonIcon}) or an image from {@link Ui.image}. */
|
|
1103
|
+
icon: BarButtonIcon | ImageRef;
|
|
1104
|
+
/** The search field's placeholder (up to 60 characters). */
|
|
1105
|
+
placeholder?: string | Text;
|
|
1106
|
+
/** Dimmed after `title` while nothing is typed (up to 80 characters). */
|
|
1107
|
+
empty?: string | Text;
|
|
1108
|
+
/** On the right of the row ("Set up a model first"; up to 40 characters). */
|
|
1109
|
+
note?: string | Text;
|
|
1110
|
+
/**
|
|
1111
|
+
* Replaces the row while nothing is typed (a running request; the cursor
|
|
1112
|
+
* starts on it); `null` or absent: none. Its run event has `status: true`.
|
|
1113
|
+
*/
|
|
1114
|
+
status?: {
|
|
1115
|
+
/** The status text (up to 80 characters). */
|
|
1116
|
+
text: string | Text;
|
|
1117
|
+
/** On the right of the row (up to 40 characters). */
|
|
1118
|
+
note?: string | Text;
|
|
1119
|
+
} | null;
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* The user activated the lead row: the data of {@link PaletteLead.onRun}.
|
|
1123
|
+
*
|
|
1124
|
+
* @since 1.7.9
|
|
1125
|
+
* @category Commands
|
|
1126
|
+
*/
|
|
1127
|
+
export interface PaletteLeadRun {
|
|
1128
|
+
/** What was typed in the palette. */
|
|
1129
|
+
query: string;
|
|
1130
|
+
/** Shift+Enter: the palette stays open. */
|
|
1131
|
+
keep: boolean;
|
|
1132
|
+
/**
|
|
1133
|
+
* The ticket of this user action, for {@link Commands.run} and
|
|
1134
|
+
* {@link PaletteLead.done}.
|
|
1135
|
+
*/
|
|
1136
|
+
ticket: string;
|
|
1137
|
+
/** The user activated the status row ({@link PaletteLeadOptions.status}), for example to stop. */
|
|
1138
|
+
status: boolean;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* The palette's lead row, from {@link Palette.lead}. Disposing it removes
|
|
1142
|
+
* the row.
|
|
1143
|
+
*
|
|
1144
|
+
* @remarks
|
|
1145
|
+
* Holds the row while the scope lives. `update` changes what it shows (a
|
|
1146
|
+
* status while a request runs, a note while it cannot run); `onRun` hears
|
|
1147
|
+
* each activation; `done` ends the ticket of a finished request.
|
|
1148
|
+
*
|
|
1149
|
+
* @capability palette.lead (built-in plugins only)
|
|
1150
|
+
*
|
|
1151
|
+
* @example Show a status while a request runs
|
|
1152
|
+
* While the plugin works on a request the row shows "Working… (Enter to
|
|
1153
|
+
* stop)"; Enter on it stops the work. The status row replaces the lead
|
|
1154
|
+
* while nothing is typed; its run event has `status: true`.
|
|
1155
|
+
* ```ts
|
|
1156
|
+
* const lead = plugin.palette.lead({ title: "Ask", icon: "search" });
|
|
1157
|
+
* let stop = new AbortController();
|
|
1158
|
+
* lead.onRun(async ({ query, ticket, status }) => {
|
|
1159
|
+
* if (status) return stop.abort(); // Enter on the status row
|
|
1160
|
+
* stop = new AbortController();
|
|
1161
|
+
* await lead.update({ title: "Ask", icon: "search", status: { text: "Working… (Enter to stop)" } });
|
|
1162
|
+
* try {
|
|
1163
|
+
* await plugin.osd.show("Asked: {}", [query]);
|
|
1164
|
+
* } finally {
|
|
1165
|
+
* await lead.update({ title: "Ask", icon: "search" });
|
|
1166
|
+
* await lead.done(ticket);
|
|
1167
|
+
* }
|
|
1168
|
+
* });
|
|
1169
|
+
* ```
|
|
1170
|
+
*
|
|
1171
|
+
* @player 0.7.6
|
|
1172
|
+
* @since 1.7.9
|
|
1173
|
+
* @category Commands
|
|
1174
|
+
*/
|
|
1175
|
+
export interface PaletteLead extends Disposable {
|
|
1176
|
+
/**
|
|
1177
|
+
* Settles when the player has the row.
|
|
1178
|
+
*
|
|
1179
|
+
* @throws `capability` (rejects) Not declared, or not a built-in plugin.
|
|
1180
|
+
* @throws `conflict` (rejects) Another plugin holds the lead.
|
|
1181
|
+
* @throws `invalid` (rejects) A text over its length.
|
|
1182
|
+
*/
|
|
1183
|
+
readonly ready: Promise<void>;
|
|
1184
|
+
/**
|
|
1185
|
+
* Replace what the row shows.
|
|
1186
|
+
*
|
|
1187
|
+
* @example See PaletteLead
|
|
1188
|
+
* {@link PaletteLead}
|
|
1189
|
+
*
|
|
1190
|
+
* @capability palette.lead (built-in plugins only)
|
|
1191
|
+
* @throws `invalid` (rejects) A text over its length.
|
|
1192
|
+
* @throws `capability` (rejects) The row was refused (see `ready`).
|
|
1193
|
+
* @since 1.7.9
|
|
1194
|
+
*/
|
|
1195
|
+
update(options: PaletteLeadOptions): Promise<void>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Listen to the user activating the row (Enter, Shift+Enter or a click).
|
|
1198
|
+
* The player starts a stopped plugin for it.
|
|
1199
|
+
*
|
|
1200
|
+
* @example Keep the palette open for another conversion
|
|
1201
|
+
* A unit converter shows its answer and, after Shift+Enter, leaves the
|
|
1202
|
+
* palette open for the next one. The listener gets the typed text and
|
|
1203
|
+
* `keep`; the player closes the palette on Enter by itself.
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* declare const lead: PaletteLead;
|
|
1206
|
+
* // ---cut---
|
|
1207
|
+
* lead.onRun(async ({ query, keep, ticket }) => {
|
|
1208
|
+
* const gigabytes = Number.parseFloat(query); // "3.5 GB in MB"
|
|
1209
|
+
* await plugin.osd.show("{} MB", [gigabytes * 1024]);
|
|
1210
|
+
* if (keep) await plugin.osd.show("Type the next value");
|
|
1211
|
+
* await lead.done(ticket);
|
|
1212
|
+
* });
|
|
1213
|
+
* ```
|
|
1214
|
+
*
|
|
1215
|
+
* @capability palette.lead (built-in plugins only)
|
|
1216
|
+
* @since 1.7.9
|
|
1217
|
+
*/
|
|
1218
|
+
onRun(listener: (run: PaletteLeadRun) => void): Disposable;
|
|
1219
|
+
/**
|
|
1220
|
+
* End a request's ticket: {@link Commands.run} refuses it from now on.
|
|
1221
|
+
*
|
|
1222
|
+
* @example End a request when it fails
|
|
1223
|
+
* A macro plugin stops at the first command that fails and ends the
|
|
1224
|
+
* ticket, so nothing more runs for this request. `done` ends the ticket
|
|
1225
|
+
* at once; without it the ticket would end 120 s after its last run.
|
|
1226
|
+
* ```ts
|
|
1227
|
+
* declare const lead: PaletteLead;
|
|
1228
|
+
* // ---cut---
|
|
1229
|
+
* lead.onRun(async ({ ticket }) => {
|
|
1230
|
+
* try {
|
|
1231
|
+
* await plugin.commands.run("host/mute", { ticket });
|
|
1232
|
+
* } catch {
|
|
1233
|
+
* await plugin.osd.show("Macro stopped"); // ticket, limit, disabled…
|
|
1234
|
+
* } finally {
|
|
1235
|
+
* await lead.done(ticket);
|
|
1236
|
+
* }
|
|
1237
|
+
* });
|
|
1238
|
+
* ```
|
|
1239
|
+
*
|
|
1240
|
+
* @capability palette.lead (built-in plugins only)
|
|
1241
|
+
* @throws `capability` (rejects) The manifest does not declare `palette.lead`.
|
|
1242
|
+
* @since 1.7.9
|
|
1243
|
+
*/
|
|
1244
|
+
done(ticket: string): Promise<void>;
|
|
834
1245
|
}
|
|
835
1246
|
/**
|
|
836
1247
|
* The core's basic playback actions (menu commands owned by the player),
|