@vestra-player/sdk 1.7.5 → 1.7.6
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 +10 -0
- package/dist/api-requests.js +0 -4
- package/dist/docs-tree.json.gz +0 -0
- package/dist/plugin/appearance.d.ts +19 -1
- package/dist/plugin/appearance.js +6 -74
- package/dist/plugin/commands.d.ts +16 -0
- package/dist/plugin/commands.js +3 -27
- package/dist/plugin/connection.d.ts +6 -0
- package/dist/plugin/connection.js +30 -2
- package/dist/plugin/index.js +2 -0
- package/dist/plugin/passes.js +0 -4
- package/dist/plugin/player/events.d.ts +2 -0
- package/dist/plugin/player/events.js +6 -2
- package/dist/plugin/player.js +8 -2
- package/dist/plugin/resolvers.js +0 -97
- package/dist/plugin/scope.d.ts +6 -0
- package/dist/plugin/scope.js +22 -3
- package/dist/plugin/testing/index.d.ts +15 -10
- package/dist/plugin/testing/index.js +15 -10
- package/dist/plugin/timeline.d.ts +2 -4
- package/dist/plugin/timeline.js +4 -27
- package/dist/plugin/types/commands.d.ts +7 -27
- package/dist/plugin/types/playback.d.ts +14 -22
- package/dist/plugin/types/sources.d.ts +0 -50
- package/dist/plugin/types/ui-locale.d.ts +4 -36
- package/dist/plugin/window.d.ts +0 -2
- package/dist/plugin/window.js +0 -4
- package/dist/wire.d.ts +1 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.6
|
|
4
|
+
|
|
5
|
+
**Who must change: plugins that call one of the five removed members — none of the player's built-ins, the plugins repository or the examples does.** `apiVersion` stays `vestra/1`; the API surface snapshot loses the five members.
|
|
6
|
+
|
|
7
|
+
- **Removed** (no deprecation period; a recount found no use anywhere): `plugin.resolvers.fileTypes` and `plugin.resolvers.onFileTypesChange` — use `plugin.player.on("resolvers.fileTypes", ({ fileTypes }) => …)`; `plugin.commands.onKeysChange` — use `plugin.player.on("commands.keys", …)` and read `plugin.commands.keys(id)` there; `plugin.timeline.onChange` — use `plugin.player.on("timeline.changed", …)` (it runs for range changes too, not only marks); `plugin.appearance.onChange` — use `plugin.player.on("appearance.changed", ({ theme }) => …)` (it runs for every event, a language change and the echo of the plugin's own `set` included). `player.on` hears only the player's events: the old `onKeysChange` also ran when the copy's first answer arrived, and none of the listeners runs for a copy's start-up value, so read the starting value once after activation, or read the copy inside a `bind` function, which follows both. Their entries in `API_REQUESTS`, `CAPABILITY_INFO` and the generated Capabilities, Events and Messages tables are gone with them.
|
|
8
|
+
- **`player.on` reads current copies**: a listener of `commands.keys`, `timeline.changed` or `appearance.changed` starts the SDK's copy that the event keeps current (`plugin.commands.keys`, `plugin.timeline.marks` and `ranges`, `plugin.appearance.theme` and `language`; the copy stays after the listener is disposed, a mirror subscription that keeps no plugin running), and every state copy now hears each event before the plugin's own listeners (`player.on`, `wire.on`), whichever was added first; a copy that throws is reported to `onError` and stops neither the other copies nor the listeners. Before, a listener added before the plugin's first read of the copy read the old value on the first event, and on every event when the copy started after it. Tests: `test/round3b-input.test.ts` (both orders), `test/command-keys.test.ts`, `test/ranges-and-osd-actions.test.ts`.
|
|
9
|
+
- `scripts/check-pack.mjs` reads the listing of Windows tar too (`\r\n` line ends), so `pack:check` runs on Windows.
|
|
10
|
+
- `TestHost.fileTypes()` and `updateFileTypes()` stay: they model the player's `resolvers.fileTypes` event, which `player.on` still hears; their doc comments no longer name the removed getter.
|
|
11
|
+
- Golden trace `host-register-keys-settle` rewritten (`UPDATE_TRACES=1`): its `onKeysChange` listener became `player.on("commands.keys")`, which runs on each `commands.keys` event instead of after the first answer, and logs what `keys("first")` reads (the event's labels each time). No wire request changed.
|
|
12
|
+
|
|
3
13
|
## 1.7.5
|
|
4
14
|
|
|
5
15
|
**Who must change: nobody.** The test host follows two player changes (seeking after the end, the playlist's Stop After Current) and reports a temporary directory it could not remove; no API change, `apiVersion` stays `vestra/1`, the API surface snapshot is unchanged.
|
package/dist/api-requests.js
CHANGED
|
@@ -72,7 +72,6 @@ export const API_REQUESTS = Object.freeze({
|
|
|
72
72
|
"Subtitles.setStyle": [{ method: "subtitles.style" }, readsSubtitles],
|
|
73
73
|
"Timeline.marks": [{ method: "timeline.marks" }],
|
|
74
74
|
"Timeline.ranges": [{ method: "timeline.marks" }],
|
|
75
|
-
"Timeline.onChange": [listen("timeline.changed")],
|
|
76
75
|
"Timeline.layer": [
|
|
77
76
|
{ method: "timeline.set" },
|
|
78
77
|
{ method: "timeline.setRanges" },
|
|
@@ -84,7 +83,6 @@ export const API_REQUESTS = Object.freeze({
|
|
|
84
83
|
"MainWindow.setPictureInPicture": [
|
|
85
84
|
{ method: "window.setPictureInPicture" },
|
|
86
85
|
],
|
|
87
|
-
"Appearance.onChange": [listen("appearance.changed")],
|
|
88
86
|
"Appearance.set": [{ method: "appearance.set" }],
|
|
89
87
|
"Appearance.setLanguage": [{ method: "appearance.setLanguage" }],
|
|
90
88
|
"Drops.provide": [{ method: "drops.provide" }],
|
|
@@ -100,10 +98,8 @@ export const API_REQUESTS = Object.freeze({
|
|
|
100
98
|
listen("window.state"),
|
|
101
99
|
],
|
|
102
100
|
"Resolvers.add": [{ method: "sourceResolvers.register" }],
|
|
103
|
-
"Resolvers.onFileTypesChange": [listen("resolvers.fileTypes")],
|
|
104
101
|
"Commands.add": [{ method: "commands.register" }],
|
|
105
102
|
"Commands.keys": [{ method: "commands.keys" }, listen("commands.keys")],
|
|
106
|
-
"Commands.onKeysChange": [listen("commands.keys")],
|
|
107
103
|
"Host.run": [{ method: "host.run" }],
|
|
108
104
|
"Windows.create": [{ method: "ui.open" }],
|
|
109
105
|
"Dialogs.confirm": [{ method: "dialogs.confirm" }],
|
package/dist/docs-tree.json.gz
CHANGED
|
Binary file
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
import type { Runtime } from "./runtime.ts";
|
|
1
2
|
import type { ScopeImpl } from "./scope.ts";
|
|
2
|
-
import type { Appearance, ThemeId } from "./types.ts";
|
|
3
|
+
import type { Appearance, LanguagePreference, ThemeId } from "./types.ts";
|
|
3
4
|
/** The palettes this SDK knows, the default first. */
|
|
4
5
|
export declare const THEMES: readonly ThemeId[];
|
|
6
|
+
/**
|
|
7
|
+
* One per plugin: the value comes with the `window.state` read before
|
|
8
|
+
* activation; with `events`, `appearance.changed` keeps it current once
|
|
9
|
+
* the plugin uses it (or listens to that event with `player.on`).
|
|
10
|
+
*/
|
|
11
|
+
declare class AppearanceService {
|
|
12
|
+
#private;
|
|
13
|
+
theme: ThemeId;
|
|
14
|
+
/** The saved interface language (the next start's). */
|
|
15
|
+
language: LanguagePreference;
|
|
16
|
+
constructor(runtime: Runtime);
|
|
17
|
+
start(): void;
|
|
18
|
+
/** An event's theme, or this plugin's own `set`: only a change counts. */
|
|
19
|
+
accept(theme: ThemeId): void;
|
|
20
|
+
}
|
|
21
|
+
export declare const appearanceOf: (runtime: Runtime) => AppearanceService;
|
|
5
22
|
export declare function appearance(scope: ScopeImpl): Appearance;
|
|
23
|
+
export {};
|
|
@@ -10,105 +10,47 @@ export const THEMES = ["vestra", "vestra-light"];
|
|
|
10
10
|
/**
|
|
11
11
|
* One per plugin: the value comes with the `window.state` read before
|
|
12
12
|
* activation; with `events`, `appearance.changed` keeps it current once
|
|
13
|
-
* the plugin uses it.
|
|
13
|
+
* the plugin uses it (or listens to that event with `player.on`).
|
|
14
14
|
*/
|
|
15
15
|
class AppearanceService {
|
|
16
16
|
#runtime;
|
|
17
17
|
theme;
|
|
18
18
|
/** The saved interface language (the next start's). */
|
|
19
19
|
language;
|
|
20
|
-
#listeners = new Set();
|
|
21
|
-
/**
|
|
22
|
-
* The theme listeners last heard (or the last event's), not the one read
|
|
23
|
-
* at start: a plugin woken from standby reads the new theme from
|
|
24
|
-
* `window.state`, then gets the `appearance.changed` the player held for
|
|
25
|
-
* it, and its listeners still hear that change. Left unset until the
|
|
26
|
-
* first event on purpose: set from the start-up read, it would hide that
|
|
27
|
-
* held change again.
|
|
28
|
-
*/
|
|
29
|
-
#notified;
|
|
30
|
-
/**
|
|
31
|
-
* The language as the start-up read and later events carried it (not
|
|
32
|
-
* `language`, which the plugin's own `setLanguage` changes before its
|
|
33
|
-
* echo arrives). The player sends `appearance.changed` once per change
|
|
34
|
-
* of the theme or of the language, each with both values: an event whose
|
|
35
|
-
* language differs from this one is a language change, and its theme is
|
|
36
|
-
* compared with `theme` as before. Only a newest event that repeats the
|
|
37
|
-
* start-up language is taken for a theme change; a plugin woken for a
|
|
38
|
-
* language change gets that too, so its listeners may hear the unchanged
|
|
39
|
-
* theme once (the event does not say what changed).
|
|
40
|
-
*/
|
|
41
|
-
#eventLanguage;
|
|
42
20
|
#started = false;
|
|
43
21
|
constructor(runtime) {
|
|
44
22
|
this.#runtime = runtime;
|
|
45
23
|
this.theme =
|
|
46
24
|
windowOf(runtime).appearance ?? "vestra";
|
|
47
25
|
this.language = preference(windowOf(runtime).language) ?? "system";
|
|
48
|
-
this.#eventLanguage = this.language;
|
|
49
26
|
}
|
|
50
27
|
start() {
|
|
51
28
|
if (this.#started)
|
|
52
29
|
return;
|
|
53
30
|
this.#started = true;
|
|
54
|
-
// A mirror:
|
|
31
|
+
// A mirror: bindings read it; it hears each event before the plugin's
|
|
32
|
+
// own listeners (`player.on`).
|
|
55
33
|
this.#runtime.on("appearance.changed", (data) => {
|
|
56
34
|
const event = data;
|
|
57
35
|
const language = preference(event?.language);
|
|
58
|
-
// An event without a language is a theme change.
|
|
59
|
-
const languageChanged = language !== undefined && language !== this.#eventLanguage;
|
|
60
|
-
if (language)
|
|
61
|
-
this.#eventLanguage = language;
|
|
62
36
|
if (language && language !== this.language) {
|
|
63
37
|
this.language = language;
|
|
64
38
|
this.#runtime.invalidate();
|
|
65
39
|
}
|
|
66
40
|
const theme = event?.theme;
|
|
67
|
-
if (
|
|
68
|
-
return;
|
|
69
|
-
if (languageChanged) {
|
|
70
|
-
// The theme came along unchanged (or this plugin set it already).
|
|
41
|
+
if (theme && THEMES.includes(theme))
|
|
71
42
|
this.accept(theme);
|
|
72
|
-
this.#notified = theme;
|
|
73
|
-
}
|
|
74
|
-
else
|
|
75
|
-
this.changed(theme);
|
|
76
43
|
}, "events", true);
|
|
77
44
|
}
|
|
78
|
-
/**
|
|
79
|
-
changed(theme) {
|
|
80
|
-
const changed = theme !== this.theme;
|
|
81
|
-
this.theme = theme;
|
|
82
|
-
if (theme !== this.#notified)
|
|
83
|
-
this.#notify(theme);
|
|
84
|
-
if (changed)
|
|
85
|
-
this.#runtime.invalidate();
|
|
86
|
-
}
|
|
87
|
-
/** After this plugin's own `set`: only a change from the current theme. */
|
|
45
|
+
/** An event's theme, or this plugin's own `set`: only a change counts. */
|
|
88
46
|
accept(theme) {
|
|
89
47
|
if (theme === this.theme)
|
|
90
48
|
return;
|
|
91
49
|
this.theme = theme;
|
|
92
|
-
this.#notify(theme);
|
|
93
50
|
this.#runtime.invalidate();
|
|
94
51
|
}
|
|
95
|
-
#notify(theme) {
|
|
96
|
-
this.#notified = theme;
|
|
97
|
-
for (const listener of [...this.#listeners])
|
|
98
|
-
listener(theme);
|
|
99
|
-
}
|
|
100
|
-
watch(listener) {
|
|
101
|
-
this.#listeners.add(listener);
|
|
102
|
-
const held = this.#runtime.hold("appearance.changed");
|
|
103
|
-
return {
|
|
104
|
-
dispose: async () => {
|
|
105
|
-
this.#listeners.delete(listener);
|
|
106
|
-
await held.dispose();
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
52
|
}
|
|
111
|
-
const appearanceOf = (runtime) => runtime.service("appearance", () => new AppearanceService(runtime));
|
|
53
|
+
export const appearanceOf = (runtime) => runtime.service("appearance", () => new AppearanceService(runtime));
|
|
112
54
|
export function appearance(scope) {
|
|
113
55
|
const service = () => appearanceOf(scope.runtime);
|
|
114
56
|
return {
|
|
@@ -117,16 +59,6 @@ export function appearance(scope) {
|
|
|
117
59
|
scope.runtime.reading("appearance.changed");
|
|
118
60
|
return service().theme;
|
|
119
61
|
},
|
|
120
|
-
onChange(listener) {
|
|
121
|
-
service().start();
|
|
122
|
-
const watch = service().watch((theme) => scope.run(listener, theme));
|
|
123
|
-
return scope.add({
|
|
124
|
-
dispose: async () => {
|
|
125
|
-
scope.forget(watch);
|
|
126
|
-
await watch.dispose();
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
62
|
async set(theme) {
|
|
131
63
|
if (!THEMES.includes(theme))
|
|
132
64
|
throw failure("invalid", `theme is ${THEMES.map((t) => `"${t}"`).join(" or ")}`);
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import type { Runtime } from "./runtime.ts";
|
|
1
2
|
import type { ScopeImpl } from "./scope.ts";
|
|
2
3
|
import type { Commands } from "./types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* One per plugin: the SDK's copy of the key labels of the plugin's own
|
|
6
|
+
* commands. Started by the first `keys` read or a `player.on("commands.keys")`: it
|
|
7
|
+
* subscribes to `commands.keys` (a mirror, unless a listener or a binding holds it), then
|
|
8
|
+
* asks once; the player pushes every later change. Answers and events carry the
|
|
9
|
+
* binding table's revision, and an older one than what the copy has is dropped.
|
|
10
|
+
*/
|
|
11
|
+
declare class KeysService {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(runtime: Runtime);
|
|
14
|
+
start(): void;
|
|
15
|
+
get(id: string): readonly string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const keysOf: (runtime: Runtime) => KeysService;
|
|
3
18
|
export declare const commands: (scope: ScopeImpl) => Commands;
|
|
19
|
+
export {};
|
package/dist/plugin/commands.js
CHANGED
|
@@ -277,8 +277,8 @@ const NONE = Object.freeze([]);
|
|
|
277
277
|
const KEYS = "commands.keys";
|
|
278
278
|
/**
|
|
279
279
|
* One per plugin: the SDK's copy of the key labels of the plugin's own
|
|
280
|
-
* commands. Started by the first `keys` read or `
|
|
281
|
-
* to `commands.keys` (a mirror, unless a listener or a binding holds it), then
|
|
280
|
+
* commands. Started by the first `keys` read or a `player.on("commands.keys")`: it
|
|
281
|
+
* subscribes to `commands.keys` (a mirror, unless a listener or a binding holds it), then
|
|
282
282
|
* asks once; the player pushes every later change. Answers and events carry the
|
|
283
283
|
* binding table's revision, and an older one than what the copy has is dropped.
|
|
284
284
|
*/
|
|
@@ -287,7 +287,6 @@ class KeysService {
|
|
|
287
287
|
#keys = new Map();
|
|
288
288
|
#revision = -1;
|
|
289
289
|
#started = false;
|
|
290
|
-
#listeners = new Set();
|
|
291
290
|
constructor(runtime) {
|
|
292
291
|
this.#runtime = runtime;
|
|
293
292
|
}
|
|
@@ -333,24 +332,12 @@ class KeysService {
|
|
|
333
332
|
if (!changed.length)
|
|
334
333
|
return;
|
|
335
334
|
this.#runtime.changed(KEYS, changed);
|
|
336
|
-
for (const listener of [...this.#listeners])
|
|
337
|
-
listener();
|
|
338
335
|
}
|
|
339
336
|
get(id) {
|
|
340
337
|
return this.#keys.get(id) ?? NONE;
|
|
341
338
|
}
|
|
342
|
-
watch(listener) {
|
|
343
|
-
this.#listeners.add(listener);
|
|
344
|
-
const held = this.#runtime.hold(KEYS);
|
|
345
|
-
return {
|
|
346
|
-
dispose: async () => {
|
|
347
|
-
this.#listeners.delete(listener);
|
|
348
|
-
await held.dispose();
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
339
|
}
|
|
353
|
-
const keysOf = (runtime) => runtime.service("commands.keys", () => new KeysService(runtime));
|
|
340
|
+
export const keysOf = (runtime) => runtime.service("commands.keys", () => new KeysService(runtime));
|
|
354
341
|
export const commands = (scope) => ({
|
|
355
342
|
add: (options) => new CommandHandle(scope, options),
|
|
356
343
|
keys(id) {
|
|
@@ -362,15 +349,4 @@ export const commands = (scope) => ({
|
|
|
362
349
|
scope.runtime.depends(KEYS, id);
|
|
363
350
|
return service.get(id);
|
|
364
351
|
},
|
|
365
|
-
onKeysChange(listener) {
|
|
366
|
-
const service = keysOf(scope.runtime);
|
|
367
|
-
service.start();
|
|
368
|
-
const watch = service.watch(() => scope.run(listener));
|
|
369
|
-
return scope.add({
|
|
370
|
-
dispose: async () => {
|
|
371
|
-
scope.forget(watch);
|
|
372
|
-
await watch.dispose();
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
},
|
|
376
352
|
});
|
|
@@ -72,6 +72,12 @@ export declare class Connection {
|
|
|
72
72
|
* changed that state elsewhere asks for it (`reread`).
|
|
73
73
|
*/
|
|
74
74
|
readonly rereads: Map<string, () => Promise<unknown>>;
|
|
75
|
+
/**
|
|
76
|
+
* Where a state copy (mirror) that threw on an event is reported: the
|
|
77
|
+
* plugin's error handlers once the root scope exists (`onError`, as for
|
|
78
|
+
* a listener), the log before.
|
|
79
|
+
*/
|
|
80
|
+
reportMirror: (error: unknown) => void;
|
|
75
81
|
/** The framework's ears ({@link StateSignals}); silent until `Runtime` sets them. */
|
|
76
82
|
signals: StateSignals;
|
|
77
83
|
/**
|
|
@@ -99,6 +99,12 @@ export class Connection {
|
|
|
99
99
|
* changed that state elsewhere asks for it (`reread`).
|
|
100
100
|
*/
|
|
101
101
|
rereads = new Map();
|
|
102
|
+
/**
|
|
103
|
+
* Where a state copy (mirror) that threw on an event is reported: the
|
|
104
|
+
* plugin's error handlers once the root scope exists (`onError`, as for
|
|
105
|
+
* a listener), the log before.
|
|
106
|
+
*/
|
|
107
|
+
reportMirror = (error) => console.error(`[${this.manifest.id}]`, error);
|
|
102
108
|
/** The framework's ears ({@link StateSignals}); silent until `Runtime` sets them. */
|
|
103
109
|
signals = SILENT;
|
|
104
110
|
/**
|
|
@@ -266,11 +272,18 @@ export class Connection {
|
|
|
266
272
|
let entry = this.#events.get(event);
|
|
267
273
|
const created = !entry;
|
|
268
274
|
if (!entry) {
|
|
269
|
-
entry = {
|
|
275
|
+
entry = {
|
|
276
|
+
listeners: new Set(),
|
|
277
|
+
mirrors: new Set(),
|
|
278
|
+
active: 0,
|
|
279
|
+
whys: new Map(),
|
|
280
|
+
};
|
|
270
281
|
this.#events.set(event, entry);
|
|
271
282
|
}
|
|
272
283
|
const group = entry;
|
|
273
284
|
group.listeners.add(listener);
|
|
285
|
+
if (mirror)
|
|
286
|
+
group.mirrors.add(listener);
|
|
274
287
|
const token = {};
|
|
275
288
|
if (!mirror) {
|
|
276
289
|
group.active++;
|
|
@@ -285,7 +298,21 @@ export class Connection {
|
|
|
285
298
|
const whys = group.told ? allWhys(group) : undefined;
|
|
286
299
|
group.toldWhy = whys?.join("\n");
|
|
287
300
|
group.off = this.host.events.subscribe(event, (data) => {
|
|
288
|
-
|
|
301
|
+
// Split once: the state copies first, each on its own (one that
|
|
302
|
+
// throws stops neither the others nor the plugin's listeners),
|
|
303
|
+
// then the plugin's listeners in order.
|
|
304
|
+
const mirrors = [];
|
|
305
|
+
const others = [];
|
|
306
|
+
for (const each of group.listeners)
|
|
307
|
+
(group.mirrors.has(each) ? mirrors : others).push(each);
|
|
308
|
+
for (const each of mirrors)
|
|
309
|
+
try {
|
|
310
|
+
each(data);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
this.reportMirror(error);
|
|
314
|
+
}
|
|
315
|
+
for (const each of others)
|
|
289
316
|
each(data);
|
|
290
317
|
}, !group.told, whys);
|
|
291
318
|
this.starting(group.off, (error) => console.error(`[${this.manifest.id}] subscribe ${event}:`, error));
|
|
@@ -299,6 +326,7 @@ export class Connection {
|
|
|
299
326
|
return;
|
|
300
327
|
listening = false;
|
|
301
328
|
group.listeners.delete(listener);
|
|
329
|
+
group.mirrors.delete(listener);
|
|
302
330
|
if (!mirror)
|
|
303
331
|
group.active--;
|
|
304
332
|
group.whys.delete(token);
|
package/dist/plugin/index.js
CHANGED
|
@@ -28,6 +28,8 @@ options) {
|
|
|
28
28
|
const root = new ScopeImpl(runtime);
|
|
29
29
|
// A runaway of the update passes goes to the plugin's error handlers.
|
|
30
30
|
runtime.passes.report = (error) => root.report(error);
|
|
31
|
+
// A state copy that throws on an event, as a listener's error would be.
|
|
32
|
+
runtime.reportMirror = (error) => root.report(error);
|
|
31
33
|
// Failures the plugin did not ask about: a property the player could not
|
|
32
34
|
// show when it rebuilt a panel or the Options window (an image removed
|
|
33
35
|
// since), a callback whose arguments it could not convert, a detached
|
package/dist/plugin/passes.js
CHANGED
|
@@ -10,10 +10,6 @@ const STATE = {
|
|
|
10
10
|
"timeline.changed": { name: "plugin.timeline.marks", when: false },
|
|
11
11
|
"commands.keys": { name: "plugin.commands.keys", when: false },
|
|
12
12
|
"playback.backend": { name: "plugin.subtitles.state", when: false },
|
|
13
|
-
"resolvers.fileTypes": {
|
|
14
|
-
name: "plugin.resolvers.fileTypes",
|
|
15
|
-
when: false,
|
|
16
|
-
},
|
|
17
13
|
};
|
|
18
14
|
/** Whether something that read `deps` may see a different result after `change`. */
|
|
19
15
|
function affected(deps, change) {
|
|
@@ -5,5 +5,7 @@ import type { Disposable, EventPayload, HostEvent } from "../types.ts";
|
|
|
5
5
|
* (`HOST_CAPABILITIES`: by event, otherwise `events`); `null`: none.
|
|
6
6
|
*/
|
|
7
7
|
export declare const EVENT_NEEDS: Readonly<Record<HostEvent, string | null>>;
|
|
8
|
+
/** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
|
|
9
|
+
export declare function checkOn(event: unknown, listener: unknown): asserts event is HostEvent;
|
|
8
10
|
/** `Player.on`: `listener` hears each `event`, with a copy of its data. */
|
|
9
11
|
export declare function playerOn<E extends HostEvent>(scope: ScopeImpl, event: E, listener: (data: EventPayload<E>) => void): Disposable;
|
|
@@ -22,12 +22,16 @@ export const EVENT_NEEDS = {
|
|
|
22
22
|
"resolvers.fileTypes": "events",
|
|
23
23
|
"video.upscaling.changed": "video.upscaling",
|
|
24
24
|
};
|
|
25
|
-
/** `Player.on
|
|
26
|
-
export function
|
|
25
|
+
/** `Player.on`'s arguments: a {@link HostEvent} name and a function. */
|
|
26
|
+
export function checkOn(event, listener) {
|
|
27
27
|
if (typeof event !== "string" || !Object.hasOwn(EVENT_NEEDS, event))
|
|
28
28
|
throw failure("invalid", `unknown event ${JSON.stringify(event)}; the events are ${Object.keys(EVENT_NEEDS).join(", ")}`);
|
|
29
29
|
if (typeof listener !== "function")
|
|
30
30
|
throw failure("invalid", "on takes an event name and a listener");
|
|
31
|
+
}
|
|
32
|
+
/** `Player.on`: `listener` hears each `event`, with a copy of its data. */
|
|
33
|
+
export function playerOn(scope, event, listener) {
|
|
34
|
+
checkOn(event, listener);
|
|
31
35
|
const watch = scope.runtime.on(event,
|
|
32
36
|
// A copy: the same data also feeds the SDK's own state copies.
|
|
33
37
|
// No full pass after it (`runQuiet`): the listener pushes its own
|
package/dist/plugin/player.js
CHANGED
|
@@ -6,7 +6,7 @@ import { HostError } from "../wire.js";
|
|
|
6
6
|
import { Latest } from "./latest.js";
|
|
7
7
|
import { abortError, failure, quiet, sleep, uncertain } from "./errors.js";
|
|
8
8
|
import { openStream, resolvedStream } from "./stream.js";
|
|
9
|
-
import { playerOn } from "./player/events.js";
|
|
9
|
+
import { checkOn, playerOn } from "./player/events.js";
|
|
10
10
|
import { validStep } from "./player/rules.js";
|
|
11
11
|
const raws = new WeakMap();
|
|
12
12
|
const empty = {
|
|
@@ -584,7 +584,13 @@ export function player(scope) {
|
|
|
584
584
|
});
|
|
585
585
|
},
|
|
586
586
|
refresh: () => service().refresh(),
|
|
587
|
-
on
|
|
587
|
+
on(event, listener) {
|
|
588
|
+
// Checked first; the copy then starts before the listener subscribes
|
|
589
|
+
// (it hears each event first in any case).
|
|
590
|
+
checkOn(event, listener);
|
|
591
|
+
scope.followCopy(event);
|
|
592
|
+
return playerOn(scope, event, listener);
|
|
593
|
+
},
|
|
588
594
|
isCurrent(state) {
|
|
589
595
|
void service().start();
|
|
590
596
|
const raw = raws.get(state);
|
package/dist/plugin/resolvers.js
CHANGED
|
@@ -4,105 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { failure, quiet } from "./errors.js";
|
|
6
6
|
import { resolvedPlayerStream } from "./player.js";
|
|
7
|
-
import { windowOf } from "./window.js";
|
|
8
7
|
const isFiles = (options) => "extensions" in options;
|
|
9
|
-
const sameTypes = (a, b) => a.length === b.length && a.every((type, i) => type === b[i]);
|
|
10
|
-
/**
|
|
11
|
-
* One per plugin: the list comes with the `window.state` read before activation
|
|
12
|
-
* and is read again when the plugin first uses it; with `events`,
|
|
13
|
-
* `resolvers.fileTypes` keeps it current.
|
|
14
|
-
*/
|
|
15
|
-
class FileTypesService {
|
|
16
|
-
#runtime;
|
|
17
|
-
types;
|
|
18
|
-
#listeners = new Set();
|
|
19
|
-
/**
|
|
20
|
-
* The list listeners last heard, not the one read at start: a plugin
|
|
21
|
-
* woken from standby reads the new list from `window.state`, then gets
|
|
22
|
-
* the `resolvers.fileTypes` the player held for it, and its listeners
|
|
23
|
-
* still hear that change. The player sends the event only when the list
|
|
24
|
-
* changed, so a first event is always news to the listeners.
|
|
25
|
-
*/
|
|
26
|
-
#notified;
|
|
27
|
-
#started = false;
|
|
28
|
-
constructor(runtime) {
|
|
29
|
-
this.#runtime = runtime;
|
|
30
|
-
this.types = Object.freeze([...(windowOf(runtime).fileTypes ?? [])]);
|
|
31
|
-
}
|
|
32
|
-
start() {
|
|
33
|
-
if (this.#started)
|
|
34
|
-
return;
|
|
35
|
-
this.#started = true;
|
|
36
|
-
// A mirror: a plugin listens through `watch` and bindings.
|
|
37
|
-
this.#runtime.on("resolvers.fileTypes", (data) => {
|
|
38
|
-
const types = data?.fileTypes;
|
|
39
|
-
if (Array.isArray(types) && types.every((t) => typeof t === "string"))
|
|
40
|
-
this.changed(types);
|
|
41
|
-
}, "events", true);
|
|
42
|
-
// What changed between the start-up read and the subscription.
|
|
43
|
-
const window = windowOf(this.#runtime);
|
|
44
|
-
void window.read().then(() => {
|
|
45
|
-
if (window.fileTypes)
|
|
46
|
-
this.accept(window.fileTypes, this.#runtime.can("events"));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/** From `resolvers.fileTypes`: listeners hear it unless they already did. */
|
|
50
|
-
changed(types) {
|
|
51
|
-
const changed = !sameTypes(types, this.types);
|
|
52
|
-
if (changed)
|
|
53
|
-
this.types = Object.freeze([...types]);
|
|
54
|
-
if (!this.#notified || !sameTypes(types, this.#notified))
|
|
55
|
-
this.#notify(types);
|
|
56
|
-
if (changed)
|
|
57
|
-
this.#runtime.invalidate();
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* From a `window.state` read: only a change from the current list.
|
|
61
|
-
* `notify`: false without `events`, whose listeners never fire.
|
|
62
|
-
*/
|
|
63
|
-
accept(types, notify = true) {
|
|
64
|
-
if (sameTypes(types, this.types))
|
|
65
|
-
return;
|
|
66
|
-
this.types = Object.freeze([...types]);
|
|
67
|
-
if (notify)
|
|
68
|
-
this.#notify(types);
|
|
69
|
-
this.#runtime.invalidate();
|
|
70
|
-
}
|
|
71
|
-
#notify(types) {
|
|
72
|
-
this.#notified = Object.freeze([...types]);
|
|
73
|
-
for (const listener of [...this.#listeners])
|
|
74
|
-
listener([...types]);
|
|
75
|
-
}
|
|
76
|
-
watch(listener) {
|
|
77
|
-
this.#listeners.add(listener);
|
|
78
|
-
const held = this.#runtime.hold("resolvers.fileTypes");
|
|
79
|
-
return {
|
|
80
|
-
dispose: async () => {
|
|
81
|
-
this.#listeners.delete(listener);
|
|
82
|
-
await held.dispose();
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const fileTypesOf = (runtime) => runtime.service("fileTypes", () => new FileTypesService(runtime));
|
|
88
8
|
export const resolvers = (scope) => ({
|
|
89
|
-
get fileTypes() {
|
|
90
|
-
const service = fileTypesOf(scope.runtime);
|
|
91
|
-
service.start();
|
|
92
|
-
scope.runtime.reading("resolvers.fileTypes");
|
|
93
|
-
return service.types;
|
|
94
|
-
},
|
|
95
|
-
onFileTypesChange(listener) {
|
|
96
|
-
const service = fileTypesOf(scope.runtime);
|
|
97
|
-
service.start();
|
|
98
|
-
const watch = service.watch((types) => scope.run(listener, types));
|
|
99
|
-
return scope.add({
|
|
100
|
-
dispose: async () => {
|
|
101
|
-
scope.forget(watch);
|
|
102
|
-
await watch.dispose();
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
9
|
add(options) {
|
|
107
10
|
const runtime = scope.runtime;
|
|
108
11
|
const registration = isFiles(options)
|
package/dist/plugin/scope.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare class ScopeImpl implements Plugin {
|
|
|
9
9
|
get dataDirectory(): string;
|
|
10
10
|
get stopReason(): StopReason | undefined;
|
|
11
11
|
get disposed(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Start the SDK's copy that `event` keeps current (`plugin.commands.keys`,
|
|
14
|
+
* `plugin.timeline`, `plugin.appearance`), for `player.on`; nothing for
|
|
15
|
+
* an event without one.
|
|
16
|
+
*/
|
|
17
|
+
followCopy(event: string): void;
|
|
12
18
|
readonly commands: import("./types.ts").Commands;
|
|
13
19
|
readonly when: import("./types.ts").When;
|
|
14
20
|
readonly windows: import("./types.ts").Windows;
|
package/dist/plugin/scope.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/** Scopes own handles. Disposal runs newest first and never throws. */
|
|
2
2
|
import { failure, toError } from "./errors.js";
|
|
3
|
-
import { commands } from "./commands.js";
|
|
3
|
+
import { commands, keysOf } from "./commands.js";
|
|
4
4
|
import { WHEN } from "./when.js";
|
|
5
5
|
import { dialogs } from "./services/dialogs.js";
|
|
6
6
|
import { ui } from "./view/image.js";
|
|
7
7
|
import { panels } from "./view/panel.js";
|
|
8
8
|
import { windows } from "./view/window.js";
|
|
9
|
-
import { timeline } from "./timeline.js";
|
|
9
|
+
import { timeline, timelineOf } from "./timeline.js";
|
|
10
10
|
import { drops } from "./drops.js";
|
|
11
|
-
import { appearance } from "./appearance.js";
|
|
11
|
+
import { appearance, appearanceOf } from "./appearance.js";
|
|
12
12
|
import { settings } from "./settings.js";
|
|
13
13
|
import { i18n } from "./language.js";
|
|
14
14
|
import { player } from "./player.js";
|
|
@@ -25,6 +25,16 @@ import { bindingsApi } from "./bindings.js";
|
|
|
25
25
|
import { trackedState } from "./state.js";
|
|
26
26
|
import { wire } from "./wire-facade.js";
|
|
27
27
|
import { clipboard, host, power, rendering, secrets, storage, system, tools, videoUpscaling, } from "./services.js";
|
|
28
|
+
/**
|
|
29
|
+
* The SDK's state copies that a player event keeps current, by event: a
|
|
30
|
+
* `player.on` listener of the event starts its copy first, so the copy
|
|
31
|
+
* already holds the event's data when the listener runs.
|
|
32
|
+
*/
|
|
33
|
+
const COPIES = {
|
|
34
|
+
"commands.keys": (runtime) => keysOf(runtime).start(),
|
|
35
|
+
"timeline.changed": (runtime) => timelineOf(runtime).start(),
|
|
36
|
+
"appearance.changed": (runtime) => appearanceOf(runtime).start(),
|
|
37
|
+
};
|
|
28
38
|
export class ScopeImpl {
|
|
29
39
|
runtime;
|
|
30
40
|
#parent;
|
|
@@ -50,6 +60,15 @@ export class ScopeImpl {
|
|
|
50
60
|
get disposed() {
|
|
51
61
|
return this.#disposed || (this.#parent?.disposed ?? false);
|
|
52
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Start the SDK's copy that `event` keeps current (`plugin.commands.keys`,
|
|
65
|
+
* `plugin.timeline`, `plugin.appearance`), for `player.on`; nothing for
|
|
66
|
+
* an event without one.
|
|
67
|
+
*/
|
|
68
|
+
followCopy(event) {
|
|
69
|
+
if (Object.hasOwn(COPIES, event))
|
|
70
|
+
COPIES[event](this.runtime);
|
|
71
|
+
}
|
|
53
72
|
commands = commands(this);
|
|
54
73
|
when = WHEN;
|
|
55
74
|
windows = windows(this);
|
|
@@ -834,7 +834,7 @@ export declare class TestHost implements Transport {
|
|
|
834
834
|
* declare const host: TestHost;
|
|
835
835
|
* // ---cut---
|
|
836
836
|
* void plugin.appearance.language; // read once: the SDK then follows it
|
|
837
|
-
* plugin.appearance.
|
|
837
|
+
* plugin.player.on("appearance.changed", () => {}); // subscribes to appearance events
|
|
838
838
|
* host.setLanguage("fr");
|
|
839
839
|
* await host.settle();
|
|
840
840
|
* assert.equal(plugin.appearance.language, "fr");
|
|
@@ -1223,8 +1223,8 @@ export declare class TestHost implements Transport {
|
|
|
1223
1223
|
* import assert from "node:assert/strict";
|
|
1224
1224
|
* declare const host: TestHost;
|
|
1225
1225
|
* // ---cut---
|
|
1226
|
-
* const themes:
|
|
1227
|
-
* plugin.appearance.
|
|
1226
|
+
* const themes: string[] = [];
|
|
1227
|
+
* plugin.player.on("appearance.changed", ({ theme }) => themes.push(theme)); // subscribes (`events`)
|
|
1228
1228
|
* host.setAppearance("vestra-light");
|
|
1229
1229
|
* await host.settle();
|
|
1230
1230
|
* assert.deepEqual(themes, ["vestra-light"]);
|
|
@@ -1763,14 +1763,14 @@ export declare class TestHost implements Transport {
|
|
|
1763
1763
|
hosts?: string[];
|
|
1764
1764
|
}[];
|
|
1765
1765
|
/**
|
|
1766
|
-
*
|
|
1766
|
+
* The list `resolvers.fileTypes` carries: the extensions of this
|
|
1767
1767
|
* plugin's file resolvers and of {@link TestHost.otherResolvers}, sorted,
|
|
1768
1768
|
* each once.
|
|
1769
1769
|
*
|
|
1770
1770
|
* @capability None.
|
|
1771
1771
|
*
|
|
1772
1772
|
* @example Check the file types a resolver adds
|
|
1773
|
-
* The test checks the list the plugin will
|
|
1773
|
+
* The test checks the list the plugin will hear in
|
|
1774
1774
|
* `resolvers.fileTypes`: the extensions of its own file resolvers and of
|
|
1775
1775
|
* `otherResolvers`, sorted, each once.
|
|
1776
1776
|
* ```ts
|
|
@@ -1790,18 +1790,23 @@ export declare class TestHost implements Transport {
|
|
|
1790
1790
|
* or stopped).
|
|
1791
1791
|
*
|
|
1792
1792
|
* @example Let another plugin's file type appear while running
|
|
1793
|
-
* Another plugin starts and adds `.ch8`; the plugin under test
|
|
1794
|
-
*
|
|
1795
|
-
* nothing: `updateFileTypes` sends
|
|
1796
|
-
* a plugin starts or stops, and
|
|
1793
|
+
* Another plugin starts and adds `.ch8`; the plugin under test, which
|
|
1794
|
+
* listens with `player.on("resolvers.fileTypes")`, then hears it.
|
|
1795
|
+
* Changing `otherResolvers` alone pushes nothing: `updateFileTypes` sends
|
|
1796
|
+
* the new list as the player does when a plugin starts or stops, and
|
|
1797
|
+
* `settle()` lets the listener run.
|
|
1797
1798
|
* ```ts
|
|
1798
1799
|
* import assert from "node:assert/strict";
|
|
1799
1800
|
* declare const host: TestHost;
|
|
1800
1801
|
* // ---cut---
|
|
1802
|
+
* const heard: string[][] = [];
|
|
1803
|
+
* // A listener of the event (`events`): each list the player sends.
|
|
1804
|
+
* plugin.player.on("resolvers.fileTypes", ({ fileTypes }) => heard.push(fileTypes));
|
|
1805
|
+
* // Another plugin starts with a resolver for .ch8 files.
|
|
1801
1806
|
* host.otherResolvers.push({ owner: "example.emulator", extensions: ["ch8"] });
|
|
1802
1807
|
* host.updateFileTypes();
|
|
1803
1808
|
* await host.settle();
|
|
1804
|
-
* assert.deepEqual(
|
|
1809
|
+
* assert.deepEqual(heard, [["ch8"]]);
|
|
1805
1810
|
* ```
|
|
1806
1811
|
*
|
|
1807
1812
|
* @capability None.
|
|
@@ -494,7 +494,7 @@ export class TestHost {
|
|
|
494
494
|
* declare const host: TestHost;
|
|
495
495
|
* // ---cut---
|
|
496
496
|
* void plugin.appearance.language; // read once: the SDK then follows it
|
|
497
|
-
* plugin.appearance.
|
|
497
|
+
* plugin.player.on("appearance.changed", () => {}); // subscribes to appearance events
|
|
498
498
|
* host.setLanguage("fr");
|
|
499
499
|
* await host.settle();
|
|
500
500
|
* assert.equal(plugin.appearance.language, "fr");
|
|
@@ -837,8 +837,8 @@ export class TestHost {
|
|
|
837
837
|
* import assert from "node:assert/strict";
|
|
838
838
|
* declare const host: TestHost;
|
|
839
839
|
* // ---cut---
|
|
840
|
-
* const themes:
|
|
841
|
-
* plugin.appearance.
|
|
840
|
+
* const themes: string[] = [];
|
|
841
|
+
* plugin.player.on("appearance.changed", ({ theme }) => themes.push(theme)); // subscribes (`events`)
|
|
842
842
|
* host.setAppearance("vestra-light");
|
|
843
843
|
* await host.settle();
|
|
844
844
|
* assert.deepEqual(themes, ["vestra-light"]);
|
|
@@ -1292,14 +1292,14 @@ export class TestHost {
|
|
|
1292
1292
|
*/
|
|
1293
1293
|
otherResolvers = [];
|
|
1294
1294
|
/**
|
|
1295
|
-
*
|
|
1295
|
+
* The list `resolvers.fileTypes` carries: the extensions of this
|
|
1296
1296
|
* plugin's file resolvers and of {@link TestHost.otherResolvers}, sorted,
|
|
1297
1297
|
* each once.
|
|
1298
1298
|
*
|
|
1299
1299
|
* @capability None.
|
|
1300
1300
|
*
|
|
1301
1301
|
* @example Check the file types a resolver adds
|
|
1302
|
-
* The test checks the list the plugin will
|
|
1302
|
+
* The test checks the list the plugin will hear in
|
|
1303
1303
|
* `resolvers.fileTypes`: the extensions of its own file resolvers and of
|
|
1304
1304
|
* `otherResolvers`, sorted, each once.
|
|
1305
1305
|
* ```ts
|
|
@@ -1328,18 +1328,23 @@ export class TestHost {
|
|
|
1328
1328
|
* or stopped).
|
|
1329
1329
|
*
|
|
1330
1330
|
* @example Let another plugin's file type appear while running
|
|
1331
|
-
* Another plugin starts and adds `.ch8`; the plugin under test
|
|
1332
|
-
*
|
|
1333
|
-
* nothing: `updateFileTypes` sends
|
|
1334
|
-
* a plugin starts or stops, and
|
|
1331
|
+
* Another plugin starts and adds `.ch8`; the plugin under test, which
|
|
1332
|
+
* listens with `player.on("resolvers.fileTypes")`, then hears it.
|
|
1333
|
+
* Changing `otherResolvers` alone pushes nothing: `updateFileTypes` sends
|
|
1334
|
+
* the new list as the player does when a plugin starts or stops, and
|
|
1335
|
+
* `settle()` lets the listener run.
|
|
1335
1336
|
* ```ts
|
|
1336
1337
|
* import assert from "node:assert/strict";
|
|
1337
1338
|
* declare const host: TestHost;
|
|
1338
1339
|
* // ---cut---
|
|
1340
|
+
* const heard: string[][] = [];
|
|
1341
|
+
* // A listener of the event (`events`): each list the player sends.
|
|
1342
|
+
* plugin.player.on("resolvers.fileTypes", ({ fileTypes }) => heard.push(fileTypes));
|
|
1343
|
+
* // Another plugin starts with a resolver for .ch8 files.
|
|
1339
1344
|
* host.otherResolvers.push({ owner: "example.emulator", extensions: ["ch8"] });
|
|
1340
1345
|
* host.updateFileTypes();
|
|
1341
1346
|
* await host.settle();
|
|
1342
|
-
* assert.deepEqual(
|
|
1347
|
+
* assert.deepEqual(heard, [["ch8"]]);
|
|
1343
1348
|
* ```
|
|
1344
1349
|
*
|
|
1345
1350
|
* @capability None.
|
|
@@ -40,7 +40,8 @@ export declare const TIMELINE_LIMITS: Readonly<{
|
|
|
40
40
|
}>;
|
|
41
41
|
/**
|
|
42
42
|
* One per plugin: read before activation (with `playback.read`), then kept
|
|
43
|
-
* current from `timeline.changed` (with `events`) once the plugin uses it
|
|
43
|
+
* current from `timeline.changed` (with `events`) once the plugin uses it
|
|
44
|
+
* (or listens to that event with `player.on`).
|
|
44
45
|
*/
|
|
45
46
|
export declare class TimelineService {
|
|
46
47
|
#private;
|
|
@@ -52,9 +53,6 @@ export declare class TimelineService {
|
|
|
52
53
|
start(): void;
|
|
53
54
|
accept(lists: WireTimeline): void;
|
|
54
55
|
read(): Promise<void>;
|
|
55
|
-
watch(listener: (marks: readonly TimelineMark[]) => void): {
|
|
56
|
-
dispose: () => Promise<void>;
|
|
57
|
-
};
|
|
58
56
|
}
|
|
59
57
|
export declare const timelineOf: (runtime: Runtime) => TimelineService;
|
|
60
58
|
export declare function timeline(scope: ScopeImpl): Timeline;
|
package/dist/plugin/timeline.js
CHANGED
|
@@ -52,13 +52,13 @@ const viewRanges = (ranges) => Object.freeze(ranges.map((range) => Object.freeze
|
|
|
52
52
|
})));
|
|
53
53
|
/**
|
|
54
54
|
* One per plugin: read before activation (with `playback.read`), then kept
|
|
55
|
-
* current from `timeline.changed` (with `events`) once the plugin uses it
|
|
55
|
+
* current from `timeline.changed` (with `events`) once the plugin uses it
|
|
56
|
+
* (or listens to that event with `player.on`).
|
|
56
57
|
*/
|
|
57
58
|
export class TimelineService {
|
|
58
59
|
#runtime;
|
|
59
60
|
marks = Object.freeze([]);
|
|
60
61
|
ranges = Object.freeze([]);
|
|
61
|
-
#listeners = new Set();
|
|
62
62
|
#started = false;
|
|
63
63
|
layer = false;
|
|
64
64
|
constructor(runtime) {
|
|
@@ -72,7 +72,8 @@ export class TimelineService {
|
|
|
72
72
|
if (this.#started)
|
|
73
73
|
return;
|
|
74
74
|
this.#started = true;
|
|
75
|
-
// A mirror:
|
|
75
|
+
// A mirror: bindings read it; it hears each event before the plugin's
|
|
76
|
+
// own listeners (`player.on`).
|
|
76
77
|
this.#runtime.on("timeline.changed", (data) => {
|
|
77
78
|
const lists = data;
|
|
78
79
|
if (lists && Array.isArray(lists.marks))
|
|
@@ -93,10 +94,6 @@ export class TimelineService {
|
|
|
93
94
|
this.marks = marks;
|
|
94
95
|
if (rangesChanged)
|
|
95
96
|
this.ranges = ranges;
|
|
96
|
-
// `onChange` follows the marks only, as before ranges existed.
|
|
97
|
-
if (marksChanged)
|
|
98
|
-
for (const listener of [...this.#listeners])
|
|
99
|
-
listener(marks);
|
|
100
97
|
this.#runtime.invalidate();
|
|
101
98
|
}
|
|
102
99
|
async read() {
|
|
@@ -104,16 +101,6 @@ export class TimelineService {
|
|
|
104
101
|
if (result)
|
|
105
102
|
this.accept(result);
|
|
106
103
|
}
|
|
107
|
-
watch(listener) {
|
|
108
|
-
this.#listeners.add(listener);
|
|
109
|
-
const held = this.#runtime.hold("timeline.changed");
|
|
110
|
-
return {
|
|
111
|
-
dispose: async () => {
|
|
112
|
-
this.#listeners.delete(listener);
|
|
113
|
-
await held.dispose();
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
104
|
}
|
|
118
105
|
export const timelineOf = (runtime) => runtime.service("timeline", () => new TimelineService(runtime));
|
|
119
106
|
export function timeline(scope) {
|
|
@@ -129,16 +116,6 @@ export function timeline(scope) {
|
|
|
129
116
|
scope.runtime.reading("timeline.changed");
|
|
130
117
|
return service().ranges;
|
|
131
118
|
},
|
|
132
|
-
onChange(listener) {
|
|
133
|
-
service().start();
|
|
134
|
-
const watch = service().watch((marks) => scope.run(listener, marks));
|
|
135
|
-
return scope.add({
|
|
136
|
-
dispose: async () => {
|
|
137
|
-
scope.forget(watch);
|
|
138
|
-
await watch.dispose();
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
119
|
layer() {
|
|
143
120
|
if (service().layer)
|
|
144
121
|
throw new Error("a plugin has one timeline layer; reuse it");
|
|
@@ -792,9 +792,14 @@ export interface Commands {
|
|
|
792
792
|
* For key hints beside a panel's controls (`KeyHint` and the `keys` of
|
|
793
793
|
* `ToolTipArea` in `@vestra/widgets.slint`). Read it in a
|
|
794
794
|
* {@link View.bind} function and the view follows every change; or
|
|
795
|
-
* listen with
|
|
795
|
+
* listen with `plugin.player.on("commands.keys", …)` and read it there
|
|
796
|
+
* (the SDK's copy already has the event's keys). The first read asks the
|
|
796
797
|
* player, and until its answer arrives (a few milliseconds) every
|
|
797
|
-
* command reads `[]`; a binding that read it runs again then.
|
|
798
|
+
* command reads `[]`; a binding that read it runs again then. That answer
|
|
799
|
+
* is not an event: a `player.on` listener hears only the player's later
|
|
800
|
+
* `commands.keys` events, so read the keys you start with in a `bind`
|
|
801
|
+
* function, which runs again when the answer arrives, not only in the
|
|
802
|
+
* listener.
|
|
798
803
|
*
|
|
799
804
|
* The plugin's own commands, and the player's own as `host/<id>`
|
|
800
805
|
* (`host/volume-up`, `host/mute`: the ids of
|
|
@@ -826,31 +831,6 @@ export interface Commands {
|
|
|
826
831
|
* @since 1.6.6
|
|
827
832
|
*/
|
|
828
833
|
keys(id: string): readonly string[];
|
|
829
|
-
/**
|
|
830
|
-
* Run `listener` after the keys of any of this plugin's commands changed
|
|
831
|
-
* (read them again with {@link Commands.keys}): the user changed or
|
|
832
|
-
* cleared a key, turned Ignore Default Shortcuts on or off, a command with
|
|
833
|
-
* keys was added or removed, or the player's first answer arrived. At most every
|
|
834
|
-
* 200 ms. A plugin in standby that listens is started for it, as for a
|
|
835
|
-
* key change in {@link Bindings.onChange}.
|
|
836
|
-
*
|
|
837
|
-
* @capability commands
|
|
838
|
-
*
|
|
839
|
-
* @example Name the current key in a status line
|
|
840
|
-
* The OSD tells the user the new key after they change it. The listener
|
|
841
|
-
* carries no data; it reads the labels with `keys`.
|
|
842
|
-
* ```ts
|
|
843
|
-
* plugin.commands.onKeysChange(() => {
|
|
844
|
-
* const [key] = plugin.commands.keys("toggle-blur");
|
|
845
|
-
* if (key) void plugin.osd.show("Blur: {}", [key]);
|
|
846
|
-
* else void plugin.osd.show("Blur has no key");
|
|
847
|
-
* });
|
|
848
|
-
* ```
|
|
849
|
-
*
|
|
850
|
-
* @player 0.7.6
|
|
851
|
-
* @since 1.6.6
|
|
852
|
-
*/
|
|
853
|
-
onKeysChange(listener: () => void): Disposable;
|
|
854
834
|
}
|
|
855
835
|
/**
|
|
856
836
|
* The core's basic playback actions (menu commands owned by the player),
|
|
@@ -174,7 +174,9 @@ export interface TimelineLayer extends Disposable {
|
|
|
174
174
|
* plugin publishes one layer with {@link Timeline.layer}; the player merges
|
|
175
175
|
* the layers by time and shows them. A new source clears every layer, so a
|
|
176
176
|
* plugin publishes again for each file. `marks` is the merged list, which
|
|
177
|
-
* any plugin can read.
|
|
177
|
+
* any plugin can read. To run code when they change, listen with
|
|
178
|
+
* `plugin.player.on("timeline.changed", …)` (needs `events`): `marks` and
|
|
179
|
+
* `ranges` already hold the event's lists when the listener runs.
|
|
178
180
|
*
|
|
179
181
|
* @capability `timeline.marks` to publish; `playback.read` to read;
|
|
180
182
|
* `events` to follow changes.
|
|
@@ -197,8 +199,7 @@ export interface Timeline {
|
|
|
197
199
|
/**
|
|
198
200
|
* Every layer's ranges merged, by start (`playback.read`). Empty on a new
|
|
199
201
|
* source. Kept current like `marks` (with `events`): read it in a
|
|
200
|
-
* {@link View.bind} function and the view follows it.
|
|
201
|
-
* when the marks change.
|
|
202
|
+
* {@link View.bind} function and the view follows it.
|
|
202
203
|
*
|
|
203
204
|
* @example Draw the published ranges in a seek bar of your own
|
|
204
205
|
* A bottom bar draws a band for every range on the seek bar, whoever
|
|
@@ -225,24 +226,6 @@ export interface Timeline {
|
|
|
225
226
|
* @since 1.6.9
|
|
226
227
|
*/
|
|
227
228
|
readonly ranges: readonly TimelineRange[];
|
|
228
|
-
/**
|
|
229
|
-
* The merged list changed (needs `events`; at most every 100 ms).
|
|
230
|
-
*
|
|
231
|
-
* @capability events and playback.read
|
|
232
|
-
*
|
|
233
|
-
* @example Follow the marks as they change
|
|
234
|
-
* A panel lists the seek bar's marks and updates when any plugin publishes
|
|
235
|
-
* or a new file clears them. The listener gets the merged list, at most
|
|
236
|
-
* every 100 ms.
|
|
237
|
-
* ```ts
|
|
238
|
-
* plugin.timeline.onChange((marks) => {
|
|
239
|
-
* console.log(marks.map((mark) => `${mark.time}s ${mark.title ?? mark.kind}`));
|
|
240
|
-
* });
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @since 1.0.0
|
|
244
|
-
*/
|
|
245
|
-
onChange(listener: (marks: readonly TimelineMark[]) => void): Disposable;
|
|
246
229
|
/**
|
|
247
230
|
* This plugin's layer (`timeline.marks`); a second call throws.
|
|
248
231
|
*
|
|
@@ -994,7 +977,16 @@ export interface Player {
|
|
|
994
977
|
*
|
|
995
978
|
* Unlike {@link Player.onChange} it does not start the SDK's copy of the
|
|
996
979
|
* state: `plugin.player.state` is not kept current by it, and the
|
|
997
|
-
* listener runs for every event, changed or not.
|
|
980
|
+
* listener runs for every event, changed or not. Three events are the
|
|
981
|
+
* exception: `commands.keys`, `timeline.changed` and `appearance.changed`
|
|
982
|
+
* start the copy they keep current (`plugin.commands.keys`,
|
|
983
|
+
* `plugin.timeline.marks` and `ranges`, `plugin.appearance.theme` and
|
|
984
|
+
* `language`), which stays for the plugin's life as a copy (not a
|
|
985
|
+
* listener: it keeps no plugin running), and the copy takes each event
|
|
986
|
+
* before the listener runs, so the listener reads the new values there.
|
|
987
|
+
* The listener hears only the player's events, never the copy's own first
|
|
988
|
+
* read: take the starting value once after activation, or read the copy
|
|
989
|
+
* in a {@link View.bind} function, which follows both. It suits pushing
|
|
998
990
|
* values yourself (`view.set` from the listener) or reading a field the
|
|
999
991
|
* SDK does not expose. Errors go to {@link Scope.onError}, as for every
|
|
1000
992
|
* handler; unlike the others, no full update pass follows it, so bound
|
|
@@ -247,54 +247,4 @@ export interface Resolvers {
|
|
|
247
247
|
* @since 1.0.0
|
|
248
248
|
*/
|
|
249
249
|
add(options: ResolverOptions): Resolver;
|
|
250
|
-
/**
|
|
251
|
-
* The extensions some plugin's file resolver handles: lower case, without the
|
|
252
|
-
* dot, sorted, each once; not who registered them. Reading needs no
|
|
253
|
-
* capability. Without `events` it is the list from when the plugin first read
|
|
254
|
-
* it. Use it to accept such files beside the player's own media types, for
|
|
255
|
-
* example in a playlist's drop or folder scan.
|
|
256
|
-
*
|
|
257
|
-
* @example Accept files that a resolver plugin can play
|
|
258
|
-
* A plugin's own file filter also accepts types other plugins turn into
|
|
259
|
-
* streams. `fileTypes` lists the extensions every running file resolver
|
|
260
|
-
* claims (lower case, no dot); the SDK keeps it current with `events`.
|
|
261
|
-
* ```ts
|
|
262
|
-
* const MEDIA = ["mp4", "mkv", "mp3"];
|
|
263
|
-
* // Extensions compare in lower case, without the dot.
|
|
264
|
-
* const accepted = (path: string) => {
|
|
265
|
-
* const extension = path.split(".").pop()?.toLowerCase() ?? "";
|
|
266
|
-
* return MEDIA.includes(extension) || plugin.resolvers.fileTypes.includes(extension);
|
|
267
|
-
* };
|
|
268
|
-
* ```
|
|
269
|
-
*
|
|
270
|
-
* @capability None.
|
|
271
|
-
* @player 0.4.2
|
|
272
|
-
* @since 1.5.8
|
|
273
|
-
*/
|
|
274
|
-
readonly fileTypes: readonly string[];
|
|
275
|
-
/**
|
|
276
|
-
* {@link Resolvers.fileTypes} changed: a file resolver was added, or its
|
|
277
|
-
* plugin stopped. Needs `events`; without it the listener never fires. When
|
|
278
|
-
* the player starts a stopped plugin for this change,
|
|
279
|
-
* {@link Resolvers.fileTypes} already has the new list at start and the
|
|
280
|
-
* listener still hears the change.
|
|
281
|
-
*
|
|
282
|
-
* @param listener - Receives the new list.
|
|
283
|
-
* @returns A handle that removes the listener.
|
|
284
|
-
*
|
|
285
|
-
* @example Say which file types became playable
|
|
286
|
-
* When a plugin with a file resolver starts or stops, the OSD lists the
|
|
287
|
-
* extra file types now accepted. The listener (which needs `events`)
|
|
288
|
-
* receives the new list each time it changes.
|
|
289
|
-
* ```ts
|
|
290
|
-
* plugin.resolvers.onFileTypesChange((types) => {
|
|
291
|
-
* void plugin.osd.show("Also accepted: {}", [plugin.i18n.list(types)]);
|
|
292
|
-
* });
|
|
293
|
-
* ```
|
|
294
|
-
*
|
|
295
|
-
* @capability `events`
|
|
296
|
-
* @player 0.4.2
|
|
297
|
-
* @since 1.5.8
|
|
298
|
-
*/
|
|
299
|
-
onFileTypesChange(listener: (types: string[]) => void): Disposable;
|
|
300
250
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Scope } from "./base.ts";
|
|
2
2
|
import type { FileResolverOptions, WebResolverOptions } from "./sources.ts";
|
|
3
3
|
import type { ConfirmOptions, Dialogs, Osd, OsdPanel } from "./ui-shell.ts";
|
|
4
|
-
import type { Disposable } from "./base.ts";
|
|
5
4
|
/**
|
|
6
5
|
* The player's palettes: `vestra`, the dark default, and `vestra-light`, a
|
|
7
6
|
* light palette whose video area stays dark. Both draw on the logo's colours.
|
|
@@ -32,6 +31,10 @@ export type ThemeId = "vestra" | "vestra-light";
|
|
|
32
31
|
* Tell the user about a change yourself (for example with
|
|
33
32
|
* {@link Osd.show}).
|
|
34
33
|
*
|
|
34
|
+
* To run code when the palette or the language changes, listen with
|
|
35
|
+
* `plugin.player.on("appearance.changed", …)` (needs `events`): `theme` and
|
|
36
|
+
* `language` already hold the event's values when the listener runs.
|
|
37
|
+
*
|
|
35
38
|
* @capability None to read `theme`; `events` to follow changes; `ui.theme`
|
|
36
39
|
* to change it.
|
|
37
40
|
*
|
|
@@ -61,41 +64,6 @@ export interface Appearance {
|
|
|
61
64
|
* plugin's own.
|
|
62
65
|
*/
|
|
63
66
|
readonly theme: ThemeId;
|
|
64
|
-
/**
|
|
65
|
-
* Run code when the palette changes.
|
|
66
|
-
*
|
|
67
|
-
* @remarks
|
|
68
|
-
* Needs `events`: without it the listener never runs for other plugins'
|
|
69
|
-
* changes. Views need no help to follow the palette; use this for things the
|
|
70
|
-
* plugin draws itself (a rendered image, colours it computes). Errors go to
|
|
71
|
-
* {@link Scope.onError}. When the player starts a stopped plugin for a
|
|
72
|
-
* palette change, {@link Appearance.theme} already has the new palette at
|
|
73
|
-
* start and the listener still hears the change. A
|
|
74
|
-
* language change does not call it, except in one case: a plugin started for
|
|
75
|
-
* a language change alone may hear the unchanged palette once, since the
|
|
76
|
-
* player's event does not say which of the two changed.
|
|
77
|
-
*
|
|
78
|
-
* @capability events
|
|
79
|
-
*
|
|
80
|
-
* @param listener - Receives the new palette.
|
|
81
|
-
* @returns A handle that removes the listener.
|
|
82
|
-
*
|
|
83
|
-
* @example Redraw a picture the plugin renders when the palette changes
|
|
84
|
-
* The plugin renders a chart image in the palette's colours and draws it
|
|
85
|
-
* again when the user or another plugin switches palettes. Views that use
|
|
86
|
-
* `Theme` follow on their own; this listener (which needs `events`) is
|
|
87
|
-
* for what the plugin draws itself.
|
|
88
|
-
* ```ts
|
|
89
|
-
* declare function renderChart(dark: boolean): Promise<void>;
|
|
90
|
-
* // ---cut---
|
|
91
|
-
* plugin.appearance.onChange((theme) => {
|
|
92
|
-
* void renderChart(theme === "vestra"); // the dark default
|
|
93
|
-
* });
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* @since 1.0.0
|
|
97
|
-
*/
|
|
98
|
-
onChange(listener: (theme: ThemeId) => void): Disposable;
|
|
99
67
|
/**
|
|
100
68
|
* Switch the palette of every view.
|
|
101
69
|
*
|
package/dist/plugin/window.d.ts
CHANGED
|
@@ -19,8 +19,6 @@ export declare class WindowService {
|
|
|
19
19
|
start(): void;
|
|
20
20
|
/** The palette, as the `window.state` reply carried it (`plugin.appearance`). */
|
|
21
21
|
appearance: string | undefined;
|
|
22
|
-
/** The file resolvers' extensions, as the reply carried them (`plugin.resolvers.fileTypes`). */
|
|
23
|
-
fileTypes: string[] | undefined;
|
|
24
22
|
/** The saved interface language, as the reply carried it (`plugin.appearance.language`). */
|
|
25
23
|
language: string | undefined;
|
|
26
24
|
accept(facts: WindowFacts): void;
|
package/dist/plugin/window.js
CHANGED
|
@@ -55,8 +55,6 @@ export class WindowService {
|
|
|
55
55
|
}
|
|
56
56
|
/** The palette, as the `window.state` reply carried it (`plugin.appearance`). */
|
|
57
57
|
appearance;
|
|
58
|
-
/** The file resolvers' extensions, as the reply carried them (`plugin.resolvers.fileTypes`). */
|
|
59
|
-
fileTypes;
|
|
60
58
|
/** The saved interface language, as the reply carried it (`plugin.appearance.language`). */
|
|
61
59
|
language;
|
|
62
60
|
accept(facts) {
|
|
@@ -64,8 +62,6 @@ export class WindowService {
|
|
|
64
62
|
this.appearance = facts.appearance;
|
|
65
63
|
if (facts.language)
|
|
66
64
|
this.language = facts.language;
|
|
67
|
-
if (Array.isArray(facts.fileTypes))
|
|
68
|
-
this.fileTypes = [...facts.fileTypes];
|
|
69
65
|
const next = view(facts);
|
|
70
66
|
if (JSON.stringify(next) === JSON.stringify(this.state))
|
|
71
67
|
return;
|
package/dist/wire.d.ts
CHANGED
|
@@ -368,7 +368,7 @@ export interface WindowFacts {
|
|
|
368
368
|
};
|
|
369
369
|
/** The palette (`plugin.appearance`), with the `window.state` reply; a newer player may name a palette this SDK does not list. */
|
|
370
370
|
appearance?: string;
|
|
371
|
-
/** The file resolvers' extensions (`
|
|
371
|
+
/** The file resolvers' extensions (as `resolvers.fileTypes` carries them). */
|
|
372
372
|
fileTypes?: string[];
|
|
373
373
|
/** The saved interface language, `"system"` or a locale. */
|
|
374
374
|
language?: string;
|
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vestra Player SDK
|
|
2
2
|
|
|
3
|
-
> @vestra-player/sdk 1.7.
|
|
3
|
+
> @vestra-player/sdk 1.7.6: write plugins for Vestra Player in TypeScript (plugin API `vestra/1`). A plugin is a folder with `manifest.json` and an entry module whose default export `activate(plugin)` the player calls. The documentation is a tree of short pages read by path, like `go doc`: the same pages and API as https://vestrasys.github.io/vestra-player-sdk/.
|
|
4
4
|
|
|
5
5
|
## Read the documentation
|
|
6
6
|
|