@vestra-player/sdk 1.9.0 → 1.10.1

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 (53) hide show
  1. package/CHANGELOG.md +44 -7
  2. package/bin/vestra-plugin.mjs +89 -8
  3. package/capability-scan.json +20 -0
  4. package/dist/api-requests.d.ts +4 -3
  5. package/dist/api-requests.js +11 -3
  6. package/dist/commands.js +1 -0
  7. package/dist/condition-table.d.ts +1889 -0
  8. package/dist/condition-table.js +562 -0
  9. package/dist/docs-tree.json.gz +0 -0
  10. package/dist/i18n-tools.d.ts +7 -0
  11. package/dist/i18n-tools.js +66 -3
  12. package/dist/player-runtime.d.ts +3 -0
  13. package/dist/player-runtime.js +3 -0
  14. package/dist/plugin/connection.d.ts +13 -2
  15. package/dist/plugin/connection.js +67 -4
  16. package/dist/plugin/index.d.ts +7 -0
  17. package/dist/plugin/index.js +13 -0
  18. package/dist/plugin/mpv.js +39 -5
  19. package/dist/plugin/player/events.d.ts +14 -5
  20. package/dist/plugin/player/events.js +19 -3
  21. package/dist/plugin/player.d.ts +16 -0
  22. package/dist/plugin/player.js +77 -1
  23. package/dist/plugin/scope.d.ts +4 -1
  24. package/dist/plugin/scope.js +8 -0
  25. package/dist/plugin/testing/commands.d.ts +5 -0
  26. package/dist/plugin/testing/commands.js +23 -24
  27. package/dist/plugin/testing/index.d.ts +134 -0
  28. package/dist/plugin/testing/index.js +180 -21
  29. package/dist/plugin/testing/media.d.ts +6 -0
  30. package/dist/plugin/testing/media.js +15 -2
  31. package/dist/plugin/testing/services.js +50 -1
  32. package/dist/plugin/testing/source-events.d.ts +28 -0
  33. package/dist/plugin/testing/source-events.js +66 -0
  34. package/dist/plugin/testing/transport.js +5 -0
  35. package/dist/plugin/testing/triggers.d.ts +82 -0
  36. package/dist/plugin/testing/triggers.js +448 -0
  37. package/dist/plugin/timeline.d.ts +3 -3
  38. package/dist/plugin/timeline.js +3 -3
  39. package/dist/plugin/triggers.d.ts +55 -0
  40. package/dist/plugin/triggers.js +233 -0
  41. package/dist/plugin/types/base.d.ts +117 -3
  42. package/dist/plugin/types/commands.d.ts +374 -1
  43. package/dist/plugin/types/packages.d.ts +10 -1
  44. package/dist/plugin/types/playback.d.ts +257 -9
  45. package/dist/plugin/types/services.d.ts +10 -4
  46. package/dist/plugin/when.d.ts +78 -4
  47. package/dist/plugin/when.js +182 -14
  48. package/dist/slint-version.d.ts +7 -0
  49. package/dist/slint-version.js +7 -0
  50. package/dist/wire.d.ts +18 -0
  51. package/dist/wire.js +12 -0
  52. package/llms.txt +4 -4
  53. package/package.json +2 -2
@@ -20,8 +20,13 @@ import type { MotionMode, MotionReason, RenderingMode, RenderingPreference, Rend
20
20
  import type { MediaJob } from "../../media.ts";
21
21
  import type { LanguagePreference, Locale, Plugin, StopReason, TemplateArgs, TextValue, ThemeId } from "../types.ts";
22
22
  import { LOCALES, LIST_SEPARATORS, TEXT_LIMITS } from "../../i18n.ts";
23
+ import type { KeptTrigger } from "./triggers.ts";
24
+ import { TRIGGER_LIMITS } from "../triggers.ts";
23
25
  /** Throw one of these from `host.handle(...)` to simulate a definite refusal. */
24
26
  export { HostError };
27
+ /** The player's limits on triggers (1.10.0), which the test host enforces as well. */
28
+ export { TRIGGER_LIMITS };
29
+ export type { KeptTrigger };
25
30
  /** The player's command caps, which the test host enforces as well. */
26
31
  export { COMMAND_LIMITS, MENU_IDS };
27
32
  /** The icons and limits of bottom-bar buttons, which the test host checks as well. */
@@ -2033,6 +2038,16 @@ export declare class TestHost implements Transport {
2033
2038
  /** The Slint version. */
2034
2039
  slint: string;
2035
2040
  };
2041
+ /**
2042
+ * `true` to run as a temporary window
2043
+ * ({@link "@vestra-player/sdk"!AppInfo.temporary | AppInfo.temporary}):
2044
+ * the plugin sees it, and `secrets.set`, `secrets.delete`,
2045
+ * `packages.install`, `packages.uninstall` and `packages.setEnabled`
2046
+ * are refused with `unavailable`, as in the player.
2047
+ *
2048
+ * @since 1.10.1
2049
+ */
2050
+ temporary?: boolean;
2036
2051
  };
2037
2052
  /**
2038
2053
  * The player's rendering choice behind `plugin.rendering`. The mode drawing
@@ -2412,6 +2427,23 @@ export declare class TestHost implements Transport {
2412
2427
  * @since 1.7.9
2413
2428
  */
2414
2429
  paletteLead: Record<string, Json> | null;
2430
+ /**
2431
+ * Every temporary window a built-in plugin opened with `app.openWindow`,
2432
+ * oldest first: the files and the process id answered
2433
+ * ({@link "@vestra-player/sdk"!App.openWindow | App.openWindow}). No
2434
+ * process starts. A
2435
+ * plugin that is not built in is refused with `capability`, as in the
2436
+ * player; the files are checked as the player does (`invalid`,
2437
+ * `missing`).
2438
+ *
2439
+ * @since 1.10.1
2440
+ */
2441
+ readonly openedWindows: {
2442
+ /** The files, as the plugin gave them. */
2443
+ paths: string[];
2444
+ /** The process id answered (made up: no process starts). */
2445
+ pid: number;
2446
+ }[];
2415
2447
  /**
2416
2448
  * Simulate the user activating the palette's lead row: Enter (`keep`:
2417
2449
  * Shift+Enter) with `query` typed, or Enter on the status row
@@ -3201,6 +3233,108 @@ export declare class TestHost implements Transport {
3201
3233
  * ```
3202
3234
  */
3203
3235
  get keepsRunning(): string[];
3236
+ /**
3237
+ * The trigger conditions the player keeps for this plugin
3238
+ * (`plugin.trigger().firesOn`), in the wire form, with their sequence
3239
+ * numbers and whether each holds now. They stay through
3240
+ * {@link TestHost.park}; {@link TestHost.upgrade} clears the unnamed ones.
3241
+ *
3242
+ * @since 1.10.0
3243
+ */
3244
+ get triggers(): readonly KeptTrigger[];
3245
+ /**
3246
+ * The test host's wall clock (Unix milliseconds), which `when.time`
3247
+ * conditions read. It starts at the real time; it moves only with
3248
+ * {@link TestHost.advance}, or when a test sets it.
3249
+ *
3250
+ * @since 1.10.0
3251
+ */
3252
+ get now(): number;
3253
+ /**
3254
+ * Set the clock to `value` (Unix milliseconds). Only the clock moves:
3255
+ * the kept conditions see the new time at their next evaluation, on
3256
+ * {@link TestHost.advance} or a state the test pushes.
3257
+ */
3258
+ set now(value: number);
3259
+ /**
3260
+ * Move the clock by `ms` milliseconds and, while the source plays
3261
+ * (`phase` `ready`, not paused), the position by `rate × ms`. Each
3262
+ * position boundary and time bound a kept condition waits for is passed
3263
+ * in its order: an `enter` or `leave` runs with the clock and the position
3264
+ * where the player would call it, and the test does not wait. The new
3265
+ * position is then pushed as `source.state`.
3266
+ *
3267
+ * @example A silence is entered 2 s before it starts
3268
+ * The source plays from 0, and the plugin's position condition has a
3269
+ * lead of 2 s before a range at 10 s. Advancing 8 s of clock plays 8 s
3270
+ * of media, so the trigger's `enter` runs on the way, at 8 s.
3271
+ * ```ts
3272
+ * import assert from "node:assert/strict";
3273
+ * declare const host: TestHost;
3274
+ * // ---cut---
3275
+ * host.setSource({ phase: "ready", duration: 60, position: 0 });
3276
+ * // … the plugin gave when.position.in([{ start: 10, end: 12 }], { lead: 2 })
3277
+ * await host.advance(8_000); // its enter ran at 8 s
3278
+ * ```
3279
+ *
3280
+ * @throws `TypeError` (rejects) `ms` is not a number of 0 or more.
3281
+ * @since 1.10.0
3282
+ */
3283
+ advance(ms: number): Promise<void>;
3284
+ /**
3285
+ * The player puts the plugin in standby: it is stopped (reason
3286
+ * `idle`); its trigger conditions and the wake events it listens to are
3287
+ * kept. A condition that flips, or a wake event, starts it again
3288
+ * (`activate()` runs anew) and delivers what waited, in order; the
3289
+ * conditions given again by `activate()` change nothing.
3290
+ *
3291
+ * @throws `Error` without a code (rejects) The plugin was not started
3292
+ * with {@link startPlugin}.
3293
+ *
3294
+ * @example A trigger condition outlives standby
3295
+ * The test puts a plugin that armed one trigger in standby, as the
3296
+ * player does when nothing uses it, and checks that the player still
3297
+ * keeps the condition that will start the plugin again.
3298
+ * ```ts
3299
+ * import assert from "node:assert/strict";
3300
+ * declare const host: TestHost;
3301
+ * // ---cut---
3302
+ * await host.park(); // stopped with reason "idle"
3303
+ * assert.equal(host.parked, true);
3304
+ * assert.equal(host.triggers.length, 1);
3305
+ * ```
3306
+ *
3307
+ * @since 1.10.0
3308
+ */
3309
+ park(): Promise<void>;
3310
+ /** The plugin is in standby ({@link TestHost.park}) and not started again yet. */
3311
+ get parked(): boolean;
3312
+ /**
3313
+ * Another version replaces the plugin: it is stopped (reason
3314
+ * `upgrade`), the conditions of its unnamed triggers are cleared, the
3315
+ * named ones kept, and it starts again with `activate` (the new
3316
+ * version's code; default: the same). A name the new version does not
3317
+ * declare is dropped when it starts.
3318
+ *
3319
+ * @throws `Error` without a code (rejects) The plugin was not started
3320
+ * with {@link startPlugin}.
3321
+ *
3322
+ * @example A named sleep timer survives an update
3323
+ * The test arms the plugin's sleep timer from its command, replaces the
3324
+ * plugin with the same code as a new version, and checks that the
3325
+ * player still keeps the condition of the trigger named `sleep`.
3326
+ * ```ts
3327
+ * import assert from "node:assert/strict";
3328
+ * declare const host: TestHost;
3329
+ * // ---cut---
3330
+ * await host.command("in45").run();
3331
+ * await host.upgrade(); // the same activate, as the new version
3332
+ * assert.ok(host.triggers.some((kept) => kept.trigger === "sleep"));
3333
+ * ```
3334
+ *
3335
+ * @since 1.10.0
3336
+ */
3337
+ upgrade(activate?: (plugin: Plugin) => unknown): Promise<void>;
3204
3338
  }
3205
3339
  /**
3206
3340
  * Activate a plugin against a test host, the way the player's runner does:
@@ -74,6 +74,7 @@ import { CAPABILITIES_REMOVED } from "../../manifest.js";
74
74
  import { MESSAGE_LIMIT } from "../../protocol.js";
75
75
  import { OSD_LIMITS } from "../osd.js";
76
76
  import { TIMELINE_LIMITS } from "../timeline.js";
77
+ import { PLAYER_SLINT } from "../../slint-version.js";
77
78
  import { SECRET_LIMITS, SESSION_STORAGE_LIMITS } from "../services.js";
78
79
  import { SUBTITLE_LIMITS } from "../subtitles.js";
79
80
  import { BINDING_INPUTS, canonical } from "../bindings.js";
@@ -93,12 +94,17 @@ import { mountOther, unmountOther, mounted, setTimelineRanges, setTimelineLayer,
93
94
  import { osdHandlers } from "./osd.js";
94
95
  import { mpvHandlers, setMpvProperty } from "./mpv.js";
95
96
  import { packageDirectories } from "./slint-types.js";
97
+ import { quitEvent } from "./source-events.js";
96
98
  import { failStream, jobsHandlers } from "./jobs.js";
97
99
  import { motionState, upscalingState, failVideoRender, failVideoShaders, upscalingDecoding, processingHandlers, } from "./processing.js";
98
100
  import { sourceIntent, startResolution, setSource, mediaHandlers, initialSource, } from "./media.js";
99
101
  import { drop, setMainWindow, servicesHandlers, sortedJson, } from "./services.js";
102
+ import { advance, keptTriggers, park, triggerState, triggersHandlers, upgrade, } from "./triggers.js";
103
+ import { TRIGGER_LIMITS } from "../triggers.js";
100
104
  /** Throw one of these from `host.handle(...)` to simulate a definite refusal. */
101
105
  export { HostError };
106
+ /** The player's limits on triggers (1.10.0), which the test host enforces as well. */
107
+ export { TRIGGER_LIMITS };
102
108
  /** The player's command caps, which the test host enforces as well. */
103
109
  export { COMMAND_LIMITS, MENU_IDS };
104
110
  /** The icons and limits of bottom-bar buttons, which the test host checks as well. */
@@ -1547,7 +1553,7 @@ export class TestHost {
1547
1553
  components: {
1548
1554
  mpv: "mpv 0.41.0",
1549
1555
  libav: { ffmpeg: "7.1" },
1550
- slint: "1.18.1",
1556
+ slint: PLAYER_SLINT,
1551
1557
  },
1552
1558
  };
1553
1559
  /**
@@ -1931,6 +1937,18 @@ export class TestHost {
1931
1937
  * @since 1.7.9
1932
1938
  */
1933
1939
  paletteLead = null;
1940
+ /**
1941
+ * Every temporary window a built-in plugin opened with `app.openWindow`,
1942
+ * oldest first: the files and the process id answered
1943
+ * ({@link "@vestra-player/sdk"!App.openWindow | App.openWindow}). No
1944
+ * process starts. A
1945
+ * plugin that is not built in is refused with `capability`, as in the
1946
+ * player; the files are checked as the player does (`invalid`,
1947
+ * `missing`).
1948
+ *
1949
+ * @since 1.10.1
1950
+ */
1951
+ openedWindows = [];
1934
1952
  /**
1935
1953
  * Simulate the user activating the palette's lead row: Enter (`keep`:
1936
1954
  * Shift+Enter) with `query` typed, or Enter on the status row
@@ -2789,7 +2807,125 @@ export class TestHost {
2789
2807
  get keepsRunning() {
2790
2808
  return keepsRunning(this, this.#inner);
2791
2809
  }
2810
+ // ------------------------------------------------------------ triggers
2811
+ /**
2812
+ * The trigger conditions the player keeps for this plugin
2813
+ * (`plugin.trigger().firesOn`), in the wire form, with their sequence
2814
+ * numbers and whether each holds now. They stay through
2815
+ * {@link TestHost.park}; {@link TestHost.upgrade} clears the unnamed ones.
2816
+ *
2817
+ * @since 1.10.0
2818
+ */
2819
+ get triggers() {
2820
+ return keptTriggers(this);
2821
+ }
2822
+ /**
2823
+ * The test host's wall clock (Unix milliseconds), which `when.time`
2824
+ * conditions read. It starts at the real time; it moves only with
2825
+ * {@link TestHost.advance}, or when a test sets it.
2826
+ *
2827
+ * @since 1.10.0
2828
+ */
2829
+ get now() {
2830
+ return triggerState(this).now;
2831
+ }
2832
+ /**
2833
+ * Set the clock to `value` (Unix milliseconds). Only the clock moves:
2834
+ * the kept conditions see the new time at their next evaluation, on
2835
+ * {@link TestHost.advance} or a state the test pushes.
2836
+ */
2837
+ set now(value) {
2838
+ triggerState(this).now = value;
2839
+ }
2840
+ /**
2841
+ * Move the clock by `ms` milliseconds and, while the source plays
2842
+ * (`phase` `ready`, not paused), the position by `rate × ms`. Each
2843
+ * position boundary and time bound a kept condition waits for is passed
2844
+ * in its order: an `enter` or `leave` runs with the clock and the position
2845
+ * where the player would call it, and the test does not wait. The new
2846
+ * position is then pushed as `source.state`.
2847
+ *
2848
+ * @example A silence is entered 2 s before it starts
2849
+ * The source plays from 0, and the plugin's position condition has a
2850
+ * lead of 2 s before a range at 10 s. Advancing 8 s of clock plays 8 s
2851
+ * of media, so the trigger's `enter` runs on the way, at 8 s.
2852
+ * ```ts
2853
+ * import assert from "node:assert/strict";
2854
+ * declare const host: TestHost;
2855
+ * // ---cut---
2856
+ * host.setSource({ phase: "ready", duration: 60, position: 0 });
2857
+ * // … the plugin gave when.position.in([{ start: 10, end: 12 }], { lead: 2 })
2858
+ * await host.advance(8_000); // its enter ran at 8 s
2859
+ * ```
2860
+ *
2861
+ * @throws `TypeError` (rejects) `ms` is not a number of 0 or more.
2862
+ * @since 1.10.0
2863
+ */
2864
+ advance(ms) {
2865
+ return advance(this, this.#inner, ms);
2866
+ }
2867
+ /**
2868
+ * The player puts the plugin in standby: it is stopped (reason
2869
+ * `idle`); its trigger conditions and the wake events it listens to are
2870
+ * kept. A condition that flips, or a wake event, starts it again
2871
+ * (`activate()` runs anew) and delivers what waited, in order; the
2872
+ * conditions given again by `activate()` change nothing.
2873
+ *
2874
+ * @throws `Error` without a code (rejects) The plugin was not started
2875
+ * with {@link startPlugin}.
2876
+ *
2877
+ * @example A trigger condition outlives standby
2878
+ * The test puts a plugin that armed one trigger in standby, as the
2879
+ * player does when nothing uses it, and checks that the player still
2880
+ * keeps the condition that will start the plugin again.
2881
+ * ```ts
2882
+ * import assert from "node:assert/strict";
2883
+ * declare const host: TestHost;
2884
+ * // ---cut---
2885
+ * await host.park(); // stopped with reason "idle"
2886
+ * assert.equal(host.parked, true);
2887
+ * assert.equal(host.triggers.length, 1);
2888
+ * ```
2889
+ *
2890
+ * @since 1.10.0
2891
+ */
2892
+ park() {
2893
+ return park(this, this.#inner);
2894
+ }
2895
+ /** The plugin is in standby ({@link TestHost.park}) and not started again yet. */
2896
+ get parked() {
2897
+ return triggerState(this).parked;
2898
+ }
2899
+ /**
2900
+ * Another version replaces the plugin: it is stopped (reason
2901
+ * `upgrade`), the conditions of its unnamed triggers are cleared, the
2902
+ * named ones kept, and it starts again with `activate` (the new
2903
+ * version's code; default: the same). A name the new version does not
2904
+ * declare is dropped when it starts.
2905
+ *
2906
+ * @throws `Error` without a code (rejects) The plugin was not started
2907
+ * with {@link startPlugin}.
2908
+ *
2909
+ * @example A named sleep timer survives an update
2910
+ * The test arms the plugin's sleep timer from its command, replaces the
2911
+ * plugin with the same code as a new version, and checks that the
2912
+ * player still keeps the condition of the trigger named `sleep`.
2913
+ * ```ts
2914
+ * import assert from "node:assert/strict";
2915
+ * declare const host: TestHost;
2916
+ * // ---cut---
2917
+ * await host.command("in45").run();
2918
+ * await host.upgrade(); // the same activate, as the new version
2919
+ * assert.ok(host.triggers.some((kept) => kept.trigger === "sleep"));
2920
+ * ```
2921
+ *
2922
+ * @since 1.10.0
2923
+ */
2924
+ upgrade(activate) {
2925
+ return upgrade(this, this.#inner, activate);
2926
+ }
2792
2927
  #defaults = {
2928
+ ...triggersHandlers(this, this.#inner),
2793
2929
  ...transportHandlers(this, this.#inner),
2794
2930
  ...commandsHandlers(this, this.#inner),
2795
2931
  ...builtinHandlers(this, this.#inner),
@@ -2913,26 +3049,42 @@ export async function startPlugin(activate, options = {}) {
2913
3049
  mkdirSync(data, { recursive: true });
2914
3050
  if (host.fileRoots.length === 0)
2915
3051
  host.fileRoots = [directory, data];
2916
- const instance = await createPlugin(host, manifest, directory, data,
2917
- // Like the player: protocol additions it takes (`app.features` set on
2918
- // the host replaces them, e.g. `[]` for an older player's behaviour).
2919
- { features: [PATCH_FEATURE], ...host.app },
2920
- // Unlike the player's runner, which logs a refused command declaration
2921
- // and activates the rest: a plugin's tests show the refusal.
2922
- { strictDeclarations: true });
2923
- await activate(instance.plugin);
2924
- // Like the player: a position or resolver another plugin holds is not an
2925
- // activation failure.
2926
- for (;;) {
2927
- try {
2928
- await instance.activated();
2929
- break;
2930
- }
2931
- catch (error) {
2932
- if (!(error instanceof Error && takenErrors.has(error)))
2933
- throw error;
3052
+ // One run of the plugin; `park` and `upgrade` (1.10.0) start another.
3053
+ const run = async (entry) => {
3054
+ const started = await createPlugin(host, manifest, directory, data,
3055
+ // Like the player: protocol additions it takes (`app.features` set on
3056
+ // the host replaces them, e.g. `[]` for an older player's behaviour).
3057
+ { features: [PATCH_FEATURE], ...host.app },
3058
+ // Unlike the player's runner, which logs a refused command declaration
3059
+ // and activates the rest: a plugin's tests show the refusal.
3060
+ { strictDeclarations: true });
3061
+ await started.activate(entry);
3062
+ // Like the player: a position or resolver another plugin holds is not an
3063
+ // activation failure.
3064
+ for (;;) {
3065
+ try {
3066
+ await started.activated();
3067
+ break;
3068
+ }
3069
+ catch (error) {
3070
+ if (!(error instanceof Error && takenErrors.has(error)))
3071
+ throw error;
3072
+ }
2934
3073
  }
2935
- }
3074
+ return started;
3075
+ };
3076
+ let instance = await run(activate);
3077
+ const triggers = triggerState(host);
3078
+ let code = activate;
3079
+ triggers.start = async (entry) => {
3080
+ if (entry)
3081
+ code = entry;
3082
+ instance = await run(code);
3083
+ };
3084
+ triggers.stop = async (reason) => {
3085
+ await instance.dispose({ reason });
3086
+ await host.settle();
3087
+ };
2936
3088
  await host.settle();
2937
3089
  tellResidency(host);
2938
3090
  // Zero declared parameters (`stop.length === 0`) and a `()` overload, so
@@ -2945,7 +3097,14 @@ export async function startPlugin(activate, options = {}) {
2945
3097
  const reason = typeof first === "object" && first !== null && "reason" in first
2946
3098
  ? first.reason
2947
3099
  : undefined;
2948
- await instance.dispose({ reason });
3100
+ // Like the player: at a quit a running plugin hears its source end.
3101
+ const quit = reason === "quit" ? quitEvent(host.source) : null;
3102
+ if (quit) {
3103
+ host.emit("source.ended", structuredClone(quit));
3104
+ await host.settle();
3105
+ }
3106
+ if (!triggers.parked)
3107
+ await instance.dispose({ reason });
2949
3108
  await host.settle();
2950
3109
  host.close();
2951
3110
  };
@@ -2,6 +2,12 @@ import type { Json } from "../../wire.ts";
2
2
  import type { SourceState } from "../../source.ts";
3
3
  import type { TestHost } from "./index.ts";
4
4
  import type { Handler, Internals } from "./internals.ts";
5
+ /**
6
+ * Broadcast the source state `host.source` became from `previous`, then
7
+ * the discrete source events it adds (`source.opening`, `source.ready`,
8
+ * `source.ended`), as the player sends them after it.
9
+ */
10
+ export declare function emitSource(host: TestHost, previous: SourceState, reload?: boolean): void;
5
11
  export declare function initialSource(): SourceState;
6
12
  export declare const readyCapabilities: {
7
13
  pause: boolean;
@@ -13,6 +13,17 @@ import { isTextValue } from "../../i18n.js";
13
13
  import { taken } from "./transport.js";
14
14
  import { declaredText, hostText } from "./i18n.js";
15
15
  import { timelineChanged } from "./layout.js";
16
+ import { sourceEvents } from "./source-events.js";
17
+ /**
18
+ * Broadcast the source state `host.source` became from `previous`, then
19
+ * the discrete source events it adds (`source.opening`, `source.ready`,
20
+ * `source.ended`), as the player sends them after it.
21
+ */
22
+ export function emitSource(host, previous, reload = false) {
23
+ host.emit("source.state", host.source);
24
+ for (const [name, data] of sourceEvents(previous, host.source, reload))
25
+ host.emit(name, structuredClone(data));
26
+ }
16
27
  export function initialSource() {
17
28
  return {
18
29
  kind: "media",
@@ -145,12 +156,13 @@ export function sourceIntent(host, inner, intent) {
145
156
  inner.selected = Number(intent.producerId);
146
157
  if (intent.kind === "open" || intent.kind === "close")
147
158
  inner.selected = null;
159
+ const previous = host.source;
148
160
  host.source = next;
149
161
  host.subtitles.source = {
150
162
  generation: next.stamp.generation,
151
163
  phase: next.phase,
152
164
  };
153
- host.emit("source.state", host.source);
165
+ emitSource(host, previous, intent.kind === "restart");
154
166
  cancelResolutions(host, inner);
155
167
  return { ticket: { stamp: next.stamp, cycle: next.cycle, owner: 1 } };
156
168
  }
@@ -389,6 +401,7 @@ export function setSource(host, inner, patch) {
389
401
  // (the player reads this as the end arrives).
390
402
  if (patch.phase === "ended" && host.source.phase !== "ended")
391
403
  inner.endKeepsPause = inner.stepped || host.source.paused;
404
+ const previous = host.source;
392
405
  host.source = {
393
406
  ...host.source,
394
407
  ...patch,
@@ -400,7 +413,7 @@ export function setSource(host, inner, patch) {
400
413
  generation: host.source.stamp.generation,
401
414
  phase: host.source.phase,
402
415
  };
403
- host.emit("source.state", host.source);
416
+ emitSource(host, previous);
404
417
  // Like the player (reference §6.3): loading shows the backdrop.
405
418
  if (patch.phase === "loading" && host.backdrop && !host.backdrop.effective)
406
419
  host.setBackdropEffective(true);
@@ -7,12 +7,46 @@
7
7
  * Internal to the SDK; not exported from `@vestra-player/sdk/testing`.
8
8
  */
9
9
  import { statSync } from "node:fs";
10
+ import { isAbsolute } from "node:path";
10
11
  import { HostError } from "../../wire.js";
11
12
  import { SESSION_STORAGE_LIMITS } from "../services.js";
12
13
  import { validStep } from "../player/rules.js";
13
14
  import { runCore, windowFacts } from "./core-actions.js";
15
+ import { builtinOnly } from "./commands.js";
14
16
  import { shownText, declaredText, shownValues, hostText } from "./i18n.js";
15
17
  import { resetWrites, writeProperty, initialValues, seeImages, kebab, typedView, checkType, inSetOrder, } from "./layout.js";
18
+ /** As the player in a temporary window (system.rs `GUEST_SECRETS`). */
19
+ const GUEST_SECRETS = "a temporary window cannot save or delete sign-in details; use the main window";
20
+ /** As the player in a temporary window (package_manager.rs `GUEST_PACKAGES`). */
21
+ const GUEST_PACKAGES = "a temporary window cannot install, update, remove, enable or disable plugins; use the main window";
22
+ /** The player's refusal of a change to the shared keychain or library in a temporary window. */
23
+ function guestRefuses(host, message) {
24
+ if (host.app.temporary === true)
25
+ throw new HostError("unavailable", message);
26
+ }
27
+ /** `app.openWindow`'s files, checked as the player does (capabilities/app_windows.rs). */
28
+ function windowPaths(paths) {
29
+ if (!Array.isArray(paths))
30
+ throw new HostError("invalid", "paths requires a list of file paths");
31
+ if (!paths.length || paths.length > 64)
32
+ throw new HostError("invalid", "paths takes 1 to 64 files");
33
+ return paths.map((path) => {
34
+ if (typeof path !== "string")
35
+ throw new HostError("invalid", "each path is a string");
36
+ if (!isAbsolute(path))
37
+ throw new HostError("invalid", `${path} is not an absolute path`);
38
+ let file = false;
39
+ try {
40
+ file = statSync(path).isFile();
41
+ }
42
+ catch {
43
+ // Not there: `missing` below, as the player.
44
+ }
45
+ if (!file)
46
+ throw new HostError("missing", `${path} is not a file`);
47
+ return path;
48
+ });
49
+ }
16
50
  /** A `plugin.storage.session` key, checked as the player does. */
17
51
  export function sessionKey(key) {
18
52
  if (typeof key !== "string" ||
@@ -109,11 +143,15 @@ export function servicesHandlers(host, inner) {
109
143
  "secrets.get": (p) => host.secrets.get(String(p.name)) ?? null,
110
144
  "secrets.set": (p) => {
111
145
  const name = String(p.name);
146
+ guestRefuses(host, GUEST_SECRETS);
112
147
  if (!host.secrets.has(name) && host.secrets.size >= 256)
113
148
  throw new HostError("limit", "a plugin stores at most 256 secret names");
114
149
  host.secrets.set(name, String(p.value));
115
150
  },
116
- "secrets.delete": (p) => void host.secrets.delete(String(p.name)),
151
+ "secrets.delete": (p) => {
152
+ guestRefuses(host, GUEST_SECRETS);
153
+ host.secrets.delete(String(p.name));
154
+ },
117
155
  // As the player (src/host/src/session_storage.rs).
118
156
  "storage.session.get": (p) => {
119
157
  const key = sessionKey(p.key);
@@ -140,6 +178,14 @@ export function servicesHandlers(host, inner) {
140
178
  rendering: host.videoRender.gpu ? "gpu" : "software",
141
179
  renderingReason: { ...host.rendering.reason },
142
180
  }),
181
+ // Built-in only; no process starts: the call is recorded.
182
+ "app.openWindow": (p) => {
183
+ builtinOnly(host);
184
+ const paths = windowPaths(p.paths);
185
+ const pid = 40000 + host.openedWindows.length;
186
+ host.openedWindows.push({ paths, pid });
187
+ return { pid };
188
+ },
143
189
  "clipboard.readText": () => host.clipboard.text,
144
190
  "clipboard.writeText": (p) => {
145
191
  if (typeof p.text !== "string")
@@ -352,6 +398,7 @@ export function servicesHandlers(host, inner) {
352
398
  },
353
399
  "packages.list": () => structuredClone(host.packages),
354
400
  "packages.setEnabled": (p) => {
401
+ guestRefuses(host, GUEST_PACKAGES);
355
402
  const id = String(p.id);
356
403
  if (id === host.manifestId && p.enabled === false)
357
404
  throw new HostError("invalid", "a plugin cannot disable itself");
@@ -394,6 +441,7 @@ export function servicesHandlers(host, inner) {
394
441
  "packages.validate": (p) => validatePackage(host, inner, String(p.directory)),
395
442
  "packages.validateArchive": (p) => validatePackage(host, inner, String(p.file)),
396
443
  "packages.install": (p) => {
444
+ guestRefuses(host, GUEST_PACKAGES);
397
445
  const manifest = host.candidates.get(String(p.token));
398
446
  if (!manifest)
399
447
  throw new HostError("stale", "unknown validation token");
@@ -448,6 +496,7 @@ export function servicesHandlers(host, inner) {
448
496
  return { operationId: String(p.requestId), status: "committed" };
449
497
  },
450
498
  "packages.uninstall": (p) => {
499
+ guestRefuses(host, GUEST_PACKAGES);
451
500
  const id = String(p.id);
452
501
  const entry = host.packages.find((each) => each.id === id);
453
502
  if (!entry)
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The discrete source events of the test host: `source.opening`,
3
+ * `source.ready` and `source.ended`, derived from two consecutive source
4
+ * states by the player's rules (player `src/host/src/source_events.rs`;
5
+ * the cases of its tests are repeated in test/source-events.test.ts).
6
+ *
7
+ * A playthrough is one load of a source (`stamp.generation`, `cycle`); it
8
+ * is in playback while `loading` or `ready`. One that leaves playback gets
9
+ * `ended` (its last state: the state that says it ended, or the last one
10
+ * before a replacement or a close); a new one gets `opening`, then
11
+ * `ready`. A new cycle of the same source that is not loading is a seek
12
+ * away from the end: it plays on, nothing opens. The test host's restart
13
+ * goes to `ready` at once, so it says it is a new load (`reload`).
14
+ *
15
+ * Internal to the SDK; not exported from `@vestra-player/sdk/testing`.
16
+ */
17
+ import type { SourceState } from "../../source.ts";
18
+ export type SourceEventName = "source.opening" | "source.ready" | "source.ended";
19
+ /** The events `next` adds to `previous`, in order. */
20
+ export declare function sourceEvents(previous: SourceState, next: SourceState, reload?: boolean): [SourceEventName, unknown][];
21
+ /**
22
+ * `source.ended` with `reason: "quit"` for a source in playback (the
23
+ * player quits; only a running plugin gets it).
24
+ */
25
+ export declare function quitEvent(state: SourceState): {
26
+ state: SourceState;
27
+ reason: string;
28
+ } | null;