@vestra-player/sdk 1.7.4 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/api-requests.js +0 -4
  3. package/dist/commands.js +1 -0
  4. package/dist/docs-tree.json.gz +0 -0
  5. package/dist/plugin/appearance.d.ts +19 -1
  6. package/dist/plugin/appearance.js +6 -74
  7. package/dist/plugin/commands.d.ts +16 -0
  8. package/dist/plugin/commands.js +3 -27
  9. package/dist/plugin/connection.d.ts +6 -0
  10. package/dist/plugin/connection.js +30 -2
  11. package/dist/plugin/index.js +2 -0
  12. package/dist/plugin/passes.js +0 -4
  13. package/dist/plugin/player/events.d.ts +2 -0
  14. package/dist/plugin/player/events.js +6 -2
  15. package/dist/plugin/player.js +8 -2
  16. package/dist/plugin/resolvers.js +0 -97
  17. package/dist/plugin/scope.d.ts +6 -0
  18. package/dist/plugin/scope.js +22 -3
  19. package/dist/plugin/testing/core-actions.d.ts +7 -0
  20. package/dist/plugin/testing/core-actions.js +66 -8
  21. package/dist/plugin/testing/index.d.ts +32 -12
  22. package/dist/plugin/testing/index.js +32 -12
  23. package/dist/plugin/testing/internals.d.ts +10 -0
  24. package/dist/plugin/testing/internals.js +10 -0
  25. package/dist/plugin/testing/media.d.ts +7 -1
  26. package/dist/plugin/testing/media.js +46 -3
  27. package/dist/plugin/testing/transport.js +3 -2
  28. package/dist/plugin/timeline.d.ts +2 -4
  29. package/dist/plugin/timeline.js +4 -27
  30. package/dist/plugin/types/commands.d.ts +8 -28
  31. package/dist/plugin/types/playback.d.ts +18 -24
  32. package/dist/plugin/types/sources.d.ts +0 -50
  33. package/dist/plugin/types/ui-locale.d.ts +4 -36
  34. package/dist/plugin/window.d.ts +0 -2
  35. package/dist/plugin/window.js +0 -4
  36. package/dist/wire.d.ts +1 -1
  37. package/llms.txt +1 -1
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
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
+
13
+ ## 1.7.5
14
+
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.
16
+
17
+ - **`TestHost`: seeking after the end**, as the player now does: the core step seeks (`seek-backward` / `seek-forward`, ← / →, `host.run` with `seconds`) are enabled at `phase: "ended"` as well as `ready`, and there they seek exactly (keyframe step mode applies only at `ready`). Any seek from the end (a core step, `player.seek`, `Scrub.seek`) returns to `phase: "ready"` (`terminalReason: null`) in a new `cycle`, as the player's session does, so an end reached again is a new end (`Media.onEnd` fires again), and plays on (`paused: false`); it stays paused when the end was reached while paused or by a frame step. Previous Frame (`frame-back`, `player.step("frame", "backward")`) after the end now moves as in the player: an exact seek one frame (`stats.video.fps`, else 30) before the position, back to `ready`, paused. A seek from the end to the end or past it (target ≥ the smaller of `position` and `duration`, less 0.5 ms; → at the end, a seek to the duration) goes nowhere: it succeeds, and the source stays `ended`, in the same cycle, and paused (`paused: true`, as keep-open holds the end). `player.step("keyframe", …)` works after the end: backward is a seek to the last `keyframes` entry before the position (none modelled: 1 ms back) that stays paused and returns to `ready`; forward goes nowhere. The pause that decides is the requested one (Play pressed just before the end: a seek from it plays on). Play/Pause at the end still restarts from 0 and plays. Tests: `test/core-actions.test.ts`.
18
+ - **`BUILTIN_COMMANDS`**: the row `vestra.playlist/playlist.repeat-once` (**Stop After Current**, outside the menu, no default key) follows the player's new Repeat mode of that name (the player 0.7.6 build with the playlist's repeat button). The playlist's four move commands stay commands with their keys (Move Up `Ctrl+ArrowUp`, Move Down `Ctrl+ArrowDown`, Move to Bottom `Ctrl+End`, panel focus; Move to Top none); their rows are unchanged. `BUILTIN_SUBMENUS` is unchanged. The table in [Reference: commands](docs/reference/commands.md#built-in-commands) follows.
19
+ - **`TestHost.close` says what it left**: a temporary directory that Windows still refuses to remove after the retries (`ENOTEMPTY`, `EBUSY`, `EPERM`; a file handle still closing) is reported on the console (`# TestHost: left <dir> (<code>)`) instead of being dropped silently; `close()` and `stop()` still never throw for it. The retries (`maxRetries: 5`, 100 ms) date from 1.5.54: an `ENOTEMPTY` at `rmSync` in `stop()` comes from an older SDK (the plugins repository runs 1.5.48). Tests: `test/testhost-close.test.ts` (a failing removal; on Windows a file another process holds open).
20
+ - Doc comments: `Player.seek`, `setStepSeek` and the `HostAction` table say what a seek after the end does.
21
+
3
22
  ## 1.7.4
4
23
 
5
24
  **Who must change: nobody.** A documentation release: no API change, `apiVersion` stays `vestra/1`, the API surface snapshot is unchanged.
@@ -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/commands.js CHANGED
@@ -361,6 +361,7 @@ vestra.playlist | playlist.add-folder | (Add Folder…)
361
361
  vestra.playlist | playlist.repeat-none | (Off)
362
362
  vestra.playlist | playlist.repeat-all | (All)
363
363
  vestra.playlist | playlist.repeat-one | (One)
364
+ vestra.playlist | playlist.repeat-once | (Stop After Current)
364
365
  vestra.playlist | playlist.shuffle | (Shuffle)
365
366
  vestra.playlist | playlist.open-list | (Open List File…)
366
367
  vestra.playlist | playlist.save-list | (Save List…)
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: a plugin listens through `watch` and bindings.
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 (!theme || !THEMES.includes(theme))
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
- /** A theme change event: listeners hear it unless they already did. */
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 {};
@@ -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 `onKeysChange`: it subscribes
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 = { listeners: new Set(), active: 0, whys: new Map() };
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
- for (const each of [...group.listeners])
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);
@@ -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
@@ -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`: `listener` hears each `event`, with a copy of its data. */
26
- export function playerOn(scope, event, listener) {
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
@@ -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: (event, listener) => playerOn(scope, event, listener),
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);
@@ -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)
@@ -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;
@@ -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);
@@ -10,6 +10,13 @@ export declare function coreFacts(host: TestHost, _inner: Internals): {
10
10
  };
11
11
  /** Why one frame that way is impossible (B07), or null; the player's rules. */
12
12
  export declare function frameCheck(host: TestHost, inner: Internals, forward: boolean): string | null;
13
+ /**
14
+ * One frame step that `frameCheck` allowed, as the player runs it: recorded
15
+ * in `steps`; back from the end an exact seek one frame (`stats` fps, else
16
+ * 30) before the position that stays paused; on the first frame nothing
17
+ * moves; any other step marks an end it reaches as keeping the pause.
18
+ */
19
+ export declare function frameStep(host: TestHost, inner: Internals, forward: boolean): void;
13
20
  /** The same enabled rules and reasons as the player's core actions. */
14
21
  export declare function coreState(host: TestHost, inner: Internals, action: string): {
15
22
  enabled: boolean;