@vestra-player/sdk 1.6.22 → 1.7.0
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 +47 -0
- package/bin/vestra-plugin.mjs +34 -12
- package/dist/api-requests.d.ts +22 -0
- package/dist/api-requests.js +38 -0
- package/dist/capability-check.d.ts +48 -0
- package/dist/capability-check.js +219 -51
- package/dist/capability-rules.d.ts +21 -0
- package/dist/capability-rules.js +32 -1
- package/dist/commands.d.ts +8 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/plugin/commands.js +43 -13
- package/dist/plugin/connection.d.ts +37 -0
- package/dist/plugin/connection.js +34 -0
- package/dist/plugin/index.js +12 -2
- package/dist/plugin/media.js +3 -1
- package/dist/plugin/packages.js +3 -1
- package/dist/plugin/passes.d.ts +38 -1
- package/dist/plugin/passes.js +89 -5
- package/dist/plugin/player/events.d.ts +9 -0
- package/dist/plugin/player/events.js +43 -0
- package/dist/plugin/player/rules.d.ts +7 -0
- package/dist/plugin/player/rules.js +11 -0
- package/dist/plugin/player.d.ts +37 -4
- package/dist/plugin/player.js +85 -12
- package/dist/plugin/resolvers.js +2 -3
- package/dist/plugin/runtime.d.ts +2 -3
- package/dist/plugin/runtime.js +8 -2
- package/dist/plugin/scope.d.ts +9 -0
- package/dist/plugin/scope.js +24 -0
- package/dist/plugin/services.js +4 -5
- package/dist/plugin/state.d.ts +3 -0
- package/dist/plugin/state.js +81 -0
- package/dist/plugin/stream.d.ts +27 -3
- package/dist/plugin/testing/core-actions.js +1 -1
- package/dist/plugin/testing/services.js +1 -1
- package/dist/plugin/types/base.d.ts +78 -2
- package/dist/plugin/types/commands.d.ts +17 -1
- package/dist/plugin/types/playback.d.ts +156 -1
- package/dist/plugin/types/plugin-wire.d.ts +589 -0
- package/dist/plugin/types/plugin-wire.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +23 -4
- package/dist/plugin/types/ui-shell.d.ts +1 -0
- package/dist/plugin/types.d.ts +4 -2
- package/dist/plugin/view/base.d.ts +10 -3
- package/dist/plugin/view/base.js +30 -6
- package/dist/plugin/view/binder.js +8 -1
- package/dist/plugin/view/writer.d.ts +49 -4
- package/dist/plugin/view/writer.js +383 -17
- package/dist/plugin/wire-facade.d.ts +4 -0
- package/dist/plugin/wire-facade.js +190 -0
- package/dist/ts-plugin.d.ts +3 -0
- package/dist/ts-plugin.js +18 -6
- package/dist/wire.d.ts +233 -20
- package/llms.txt +3 -3
- package/package.json +1 -1
- package/slint/vestra/focus.slint +33 -0
package/dist/plugin/runtime.js
CHANGED
|
@@ -19,10 +19,16 @@ export class Runtime extends Connection {
|
|
|
19
19
|
super(transport, manifest, directory, dataDirectory, app, options);
|
|
20
20
|
this.passes = new Passes(this);
|
|
21
21
|
this.counts = this.passes.counts;
|
|
22
|
+
const passes = this.passes;
|
|
23
|
+
this.signals = {
|
|
24
|
+
read: (key, field) => passes.depends(key, field),
|
|
25
|
+
changed: (key, fields) => passes.changed(key, fields),
|
|
26
|
+
invalidate: () => passes.invalidate(),
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
/** {@link Passes.bind} */
|
|
24
|
-
bind(evaluate) {
|
|
25
|
-
return this.passes.bind(evaluate);
|
|
30
|
+
bind(evaluate, slot) {
|
|
31
|
+
return this.passes.bind(evaluate, slot);
|
|
26
32
|
}
|
|
27
33
|
/** {@link Passes.reading} */
|
|
28
34
|
reading(event) {
|
package/dist/plugin/scope.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare class ScopeImpl implements Plugin {
|
|
|
46
46
|
readonly appearance: import("./types.ts").Appearance;
|
|
47
47
|
readonly settings: import("./types.ts").Settings;
|
|
48
48
|
readonly i18n: import("./types.ts").I18n;
|
|
49
|
+
readonly wire: import("./types.ts").Wire;
|
|
49
50
|
get app(): import("./types.ts").App;
|
|
50
51
|
scope(): Scope;
|
|
51
52
|
add<T extends Disposable>(item: T): T;
|
|
@@ -64,6 +65,14 @@ export declare class ScopeImpl implements Plugin {
|
|
|
64
65
|
* anyway, and a full pass follows within `SAFETY_PASS_MS`.
|
|
65
66
|
*/
|
|
66
67
|
runOn(change: Change, handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Run a listener that pushes its own values (`player.on`, SDK 1.7.0)
|
|
70
|
+
* like `run`, except that no full pass follows it: what it writes to
|
|
71
|
+
* `plugin.state` runs the passes for its readers, and for anything else
|
|
72
|
+
* the plugin calls `update()`. Its reads are not counted as a binding's.
|
|
73
|
+
*/
|
|
74
|
+
runQuiet(handler: (...args: never[]) => unknown, ...args: unknown[]): void;
|
|
67
75
|
update(): void;
|
|
76
|
+
state<T extends object>(initial: T): T;
|
|
68
77
|
dispose(): Promise<void>;
|
|
69
78
|
}
|
package/dist/plugin/scope.js
CHANGED
|
@@ -22,6 +22,8 @@ import { packages } from "./packages.js";
|
|
|
22
22
|
import { osd } from "./osd.js";
|
|
23
23
|
import { mainWindow } from "./window.js";
|
|
24
24
|
import { bindingsApi } from "./bindings.js";
|
|
25
|
+
import { trackedState } from "./state.js";
|
|
26
|
+
import { wire } from "./wire-facade.js";
|
|
25
27
|
import { clipboard, host, power, rendering, secrets, storage, system, tools, videoUpscaling, } from "./services.js";
|
|
26
28
|
export class ScopeImpl {
|
|
27
29
|
runtime;
|
|
@@ -83,6 +85,7 @@ export class ScopeImpl {
|
|
|
83
85
|
appearance = appearance(this);
|
|
84
86
|
settings = settings(this);
|
|
85
87
|
i18n = i18n(this);
|
|
88
|
+
wire = wire(this);
|
|
86
89
|
get app() {
|
|
87
90
|
return this.runtime.app;
|
|
88
91
|
}
|
|
@@ -180,9 +183,30 @@ export class ScopeImpl {
|
|
|
180
183
|
if (full)
|
|
181
184
|
this.update();
|
|
182
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Run a listener that pushes its own values (`player.on`, SDK 1.7.0)
|
|
188
|
+
* like `run`, except that no full pass follows it: what it writes to
|
|
189
|
+
* `plugin.state` runs the passes for its readers, and for anything else
|
|
190
|
+
* the plugin calls `update()`. Its reads are not counted as a binding's.
|
|
191
|
+
*/
|
|
192
|
+
runQuiet(handler, ...args) {
|
|
193
|
+
if (this.disposed)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
const { value } = this.runtime.observe(() => handler(...args));
|
|
197
|
+
if (value instanceof Promise)
|
|
198
|
+
value.catch((error) => this.report(error));
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
this.report(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
183
204
|
update() {
|
|
184
205
|
this.runtime.invalidate();
|
|
185
206
|
}
|
|
207
|
+
state(initial) {
|
|
208
|
+
return trackedState(this, initial);
|
|
209
|
+
}
|
|
186
210
|
async dispose() {
|
|
187
211
|
if (this.#disposed)
|
|
188
212
|
return;
|
package/dist/plugin/services.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdir, open, rename, rm, stat } from "node:fs/promises";
|
|
|
9
9
|
import { join, resolve } from "node:path";
|
|
10
10
|
import { failure } from "./errors.js";
|
|
11
11
|
import { systemServices } from "./local.js";
|
|
12
|
-
import {
|
|
12
|
+
import { validStep } from "./player/rules.js";
|
|
13
13
|
const MAX_OUTPUT = 16 * 1024 * 1024;
|
|
14
14
|
export const clipboard = (scope) => ({
|
|
15
15
|
readText: () => scope.runtime.host.clipboard.readText(),
|
|
@@ -45,11 +45,10 @@ export const host = (scope) => ({
|
|
|
45
45
|
throw failure("invalid", "seconds must be 0.1–3600 in tenths");
|
|
46
46
|
}
|
|
47
47
|
await scope.runtime.host.host.run(action, seconds);
|
|
48
|
-
// Like the player's own controls: `player.state` shows the result
|
|
48
|
+
// Like the player's own controls: `player.state` shows the result (the
|
|
49
|
+
// player's state copy registered how to read it again).
|
|
49
50
|
if (scope.runtime.can("playback.read"))
|
|
50
|
-
await
|
|
51
|
-
.refresh()
|
|
52
|
-
.catch(() => { });
|
|
51
|
+
await scope.runtime.reread("source.state");
|
|
53
52
|
},
|
|
54
53
|
});
|
|
55
54
|
export const power = (scope) => ({
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plugin.state(initial)` (L2, the framework; refactor plan §3.5, SDK
|
|
3
|
+
* 1.7.0): plugin-owned state the update passes follow like the SDK's own
|
|
4
|
+
* state copies. A read of a field inside what a pass evaluates records
|
|
5
|
+
* `(store, field)` through `Runtime.depends`, the mechanism
|
|
6
|
+
* `plugin.player.state` uses; a write of a field that changes it
|
|
7
|
+
* (`Object.is`) reports `Runtime.changed(store, [field])`, so the next pass
|
|
8
|
+
* is a precise one that evaluates only that field's readers. One level:
|
|
9
|
+
* the value of a field is compared by identity, nothing inside it is
|
|
10
|
+
* tracked. It belongs to the calling scope: once that scope is disposed
|
|
11
|
+
* the object is a plain one, read and written without tracking.
|
|
12
|
+
*/
|
|
13
|
+
import { failure } from "./errors.js";
|
|
14
|
+
/** Each store's key in the passes' field tracking (`state:1`, `state:2`…). */
|
|
15
|
+
let stores = 0;
|
|
16
|
+
/** A plain object: its prototype is `Object.prototype` or `null`. */
|
|
17
|
+
function plain(value) {
|
|
18
|
+
if (value === null || typeof value !== "object")
|
|
19
|
+
return false;
|
|
20
|
+
const proto = Object.getPrototypeOf(value);
|
|
21
|
+
return proto === Object.prototype || proto === null;
|
|
22
|
+
}
|
|
23
|
+
/** `Scope.state`: a tracked copy of `initial`'s own fields. */
|
|
24
|
+
export function trackedState(scope, initial) {
|
|
25
|
+
if (!plain(initial))
|
|
26
|
+
throw failure("invalid", "state takes a plain object of fields and their first values");
|
|
27
|
+
const runtime = scope.runtime;
|
|
28
|
+
const key = `state:${++stores}`;
|
|
29
|
+
const target = { ...initial };
|
|
30
|
+
const live = () => !scope.disposed;
|
|
31
|
+
const depends = (field) => {
|
|
32
|
+
if (live())
|
|
33
|
+
runtime.depends(key, field);
|
|
34
|
+
};
|
|
35
|
+
const changed = (field) => {
|
|
36
|
+
if (live())
|
|
37
|
+
runtime.changed(key, [field]);
|
|
38
|
+
};
|
|
39
|
+
return new Proxy(target, {
|
|
40
|
+
get(store, field, receiver) {
|
|
41
|
+
if (typeof field === "string")
|
|
42
|
+
depends(field);
|
|
43
|
+
return Reflect.get(store, field, receiver);
|
|
44
|
+
},
|
|
45
|
+
has(store, field) {
|
|
46
|
+
if (typeof field === "string")
|
|
47
|
+
depends(field);
|
|
48
|
+
return Reflect.has(store, field);
|
|
49
|
+
},
|
|
50
|
+
ownKeys(store) {
|
|
51
|
+
// The list of fields: any change of the store counts.
|
|
52
|
+
depends();
|
|
53
|
+
return Reflect.ownKeys(store);
|
|
54
|
+
},
|
|
55
|
+
set(store, field, value) {
|
|
56
|
+
const had = Object.hasOwn(store, field);
|
|
57
|
+
const before = store[field];
|
|
58
|
+
store[field] = value;
|
|
59
|
+
if (typeof field === "string" && (!had || !Object.is(before, value)))
|
|
60
|
+
changed(field);
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
deleteProperty(store, field) {
|
|
64
|
+
const had = Object.hasOwn(store, field);
|
|
65
|
+
delete store[field];
|
|
66
|
+
if (typeof field === "string" && had)
|
|
67
|
+
changed(field);
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
defineProperty(store, field, descriptor) {
|
|
71
|
+
const had = Object.hasOwn(store, field);
|
|
72
|
+
const before = store[field];
|
|
73
|
+
const done = Reflect.defineProperty(store, field, descriptor);
|
|
74
|
+
if (done &&
|
|
75
|
+
typeof field === "string" &&
|
|
76
|
+
(!had || !Object.is(before, store[field])))
|
|
77
|
+
changed(field);
|
|
78
|
+
return done;
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
package/dist/plugin/stream.d.ts
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
|
-
import type { PlayerService } from "./player.ts";
|
|
2
1
|
import type { ScopeImpl } from "./scope.ts";
|
|
3
2
|
import type { ResolvedProducer } from "../source-resolvers.ts";
|
|
3
|
+
import type { SourceIntent, SourceState, SourceTicket } from "../source.ts";
|
|
4
|
+
import type { Wire } from "../wire.ts";
|
|
4
5
|
import type { ResolvedStream, Stream, StreamOptions } from "./types.ts";
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The player's source as a stream uses it: submit and close it, read it
|
|
8
|
+
* again. `player.ts` passes its state copy (`PlayerService`), which follows
|
|
9
|
+
* the source while a stream exists; this file depends only on this shape,
|
|
10
|
+
* not on the copy (refactor plan §2.1).
|
|
11
|
+
*/
|
|
12
|
+
export interface StreamSource {
|
|
13
|
+
readonly runtime: {
|
|
14
|
+
readonly host: Wire;
|
|
15
|
+
can(capability: string): boolean;
|
|
16
|
+
};
|
|
17
|
+
/** The newest source state seen. */
|
|
18
|
+
readonly raw: SourceState;
|
|
19
|
+
/** The same, as the plugin sees it (`error` in the player's words). */
|
|
20
|
+
readonly state: {
|
|
21
|
+
readonly error: string | null;
|
|
22
|
+
};
|
|
23
|
+
refresh(): Promise<unknown>;
|
|
24
|
+
submit(intent: SourceIntent, options?: {
|
|
25
|
+
accepted?: (ticket: SourceTicket) => void;
|
|
26
|
+
}): Promise<SourceTicket>;
|
|
27
|
+
closeIfCurrent(generation: number): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function openStream(scope: ScopeImpl, service: StreamSource, options: StreamOptions): Promise<Stream>;
|
|
6
30
|
/**
|
|
7
31
|
* A file resolver's stream (`ResolvedStream`): prepared and prerolled while
|
|
8
32
|
* the open waits, then handed to the host as the answer. Once the host
|
|
@@ -11,4 +35,4 @@ export declare function openStream(scope: ScopeImpl, service: PlayerService, opt
|
|
|
11
35
|
* during activation (the open was replaced or closed, the plugin stopped),
|
|
12
36
|
* the producer is released and `started` is never called.
|
|
13
37
|
*/
|
|
14
|
-
export declare function resolvedStream(scope: ScopeImpl, service:
|
|
38
|
+
export declare function resolvedStream(scope: ScopeImpl, service: StreamSource, stream: ResolvedStream, signal: AbortSignal): Promise<ResolvedProducer>;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Internal to the SDK; not exported from `@vestra-player/sdk/testing`.
|
|
8
8
|
*/
|
|
9
9
|
import { HostError } from "../../wire.js";
|
|
10
|
-
import { validStep } from "../player.js";
|
|
10
|
+
import { validStep } from "../player/rules.js";
|
|
11
11
|
import { hostText } from "./i18n.js";
|
|
12
12
|
import { sourceIntent, audioCondition } from "./media.js";
|
|
13
13
|
export function coreFacts(host, _inner) {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { statSync } from "node:fs";
|
|
10
10
|
import { HostError } from "../../wire.js";
|
|
11
11
|
import { SESSION_STORAGE_LIMITS } from "../services.js";
|
|
12
|
-
import { validStep } from "../player.js";
|
|
12
|
+
import { validStep } from "../player/rules.js";
|
|
13
13
|
import { runCore, windowFacts } from "./core-actions.js";
|
|
14
14
|
import { shownText, declaredText, shownValues, hostText } from "./i18n.js";
|
|
15
15
|
import { resetWrites, writeProperty, initialValues, seeImages, kebab, } from "./layout.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Command } from "./commands.ts";
|
|
1
|
+
import type { Command, CommandOptions } from "./commands.ts";
|
|
2
2
|
import type { PackageCandidate, PluginInfo } from "./packages.ts";
|
|
3
3
|
import type { Conditional, Media, Stream } from "./playback.ts";
|
|
4
4
|
import type {
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
} from "./services.ts";
|
|
9
9
|
import type { ExportJob, Snapshot } from "./snapshots.ts";
|
|
10
10
|
import type { Resolver } from "./sources.ts";
|
|
11
|
-
import type { PropValue } from "./ui-content.ts";
|
|
11
|
+
import type { PropValue, View } from "./ui-content.ts";
|
|
12
12
|
import type { Panel, Window } from "./ui-layout.ts";
|
|
13
13
|
import type { Bindings, Commands, Host, When } from "./commands.ts";
|
|
14
14
|
import type { Packages } from "./packages.ts";
|
|
@@ -22,6 +22,7 @@ import type { Ui } from "./ui-content.ts";
|
|
|
22
22
|
import type { Drops, Windows } from "./ui-layout.ts";
|
|
23
23
|
import type { Appearance, I18n } from "./ui-locale.ts";
|
|
24
24
|
import type { Dialogs, Osd, Panels, Settings } from "./ui-shell.ts";
|
|
25
|
+
import type { Wire } from "./plugin-wire.ts";
|
|
25
26
|
/**
|
|
26
27
|
* Anything that owns player-side or local resources: every handle the API
|
|
27
28
|
* returns (commands, windows, panels, filters, snapshots, listeners…).
|
|
@@ -352,6 +353,16 @@ export interface Scope extends Disposable {
|
|
|
352
353
|
readonly i18n: I18n;
|
|
353
354
|
/** Pages in the player's options window (`ui.settings`). */
|
|
354
355
|
readonly settings: Settings;
|
|
356
|
+
/**
|
|
357
|
+
* Direct messages to the player: requests by method name, raw events,
|
|
358
|
+
* direct property writes, bare command registrations (SDK 1.7.0).
|
|
359
|
+
* Experimental: the wire protocol is not semver; this member changes
|
|
360
|
+
* with versions. See {@link Wire}.
|
|
361
|
+
*
|
|
362
|
+
* @experimental
|
|
363
|
+
* @since 1.7.0
|
|
364
|
+
*/
|
|
365
|
+
readonly wire: Wire;
|
|
355
366
|
/**
|
|
356
367
|
* A child scope; disposing it releases only what was created through it.
|
|
357
368
|
* The child is itself owned by this scope.
|
|
@@ -513,6 +524,71 @@ export interface Scope extends Disposable {
|
|
|
513
524
|
* @since 1.0.0
|
|
514
525
|
*/
|
|
515
526
|
update(): void;
|
|
527
|
+
/**
|
|
528
|
+
* Plugin-owned state that bound values follow by themselves: reading a
|
|
529
|
+
* field in a `bind` function or a command's state function records it,
|
|
530
|
+
* and writing that field re-evaluates exactly those readers.
|
|
531
|
+
*
|
|
532
|
+
* @remarks
|
|
533
|
+
* Returns an object of the same shape as `initial` (a copy of its own
|
|
534
|
+
* fields; `initial` itself is not tracked). A read inside a
|
|
535
|
+
* {@link View.bind} function or a {@link CommandOptions} field given as a
|
|
536
|
+
* function is recorded like a read of `plugin.player.state`; anywhere
|
|
537
|
+
* else (a handler, an `onChange` listener, a timer) it is a plain read,
|
|
538
|
+
* and writing there is how a handler updates what is bound. A write of a
|
|
539
|
+
* field (or a new field, or `delete`) schedules one
|
|
540
|
+
* update pass for the microtask turn, however many fields change, and that
|
|
541
|
+
* pass evaluates only the readers of what changed, not every binding and
|
|
542
|
+
* command as {@link Scope.update} does. Writing a value equal to the
|
|
543
|
+
* current one (`Object.is`) changes nothing.
|
|
544
|
+
*
|
|
545
|
+
* Tracking is one level deep: a field holding an object or array is
|
|
546
|
+
* compared by identity, so changing something inside it is not seen.
|
|
547
|
+
* Replace the object instead (`st.list = [...st.list, item]`). Do not
|
|
548
|
+
* write a field from a `bind` function that reads it: each write runs the
|
|
549
|
+
* function again; the SDK stops such a loop after 100 passes in a row and
|
|
550
|
+
* reports it to {@link Scope.onError} once (`limit`). The limit counts
|
|
551
|
+
* passes, not loops: a chain of bindings that is not a loop but deeper
|
|
552
|
+
* than 100 (each writing a field the next one reads) is cut the same
|
|
553
|
+
* way: what the dropped pass would have evaluated waits for the next full
|
|
554
|
+
* pass (after a handler, or {@link Scope.update}). Keep derived values in
|
|
555
|
+
* one function instead of chaining fields.
|
|
556
|
+
*
|
|
557
|
+
* The object is a `Proxy`: spread, `Object.keys` and `JSON.stringify` give
|
|
558
|
+
* its values; `structuredClone` does not take it (clone `{ ...st }`). It
|
|
559
|
+
* belongs to this scope: once the scope is disposed it is a plain object,
|
|
560
|
+
* whose reads and writes still work but are no longer recorded and
|
|
561
|
+
* schedule no pass (as other handles of a disposed scope go quiet).
|
|
562
|
+
* `update()` stays for state the SDK cannot see.
|
|
563
|
+
*
|
|
564
|
+
* @param initial - The fields and their first values: a plain object.
|
|
565
|
+
* @returns The tracked object.
|
|
566
|
+
*
|
|
567
|
+
* @throws `invalid` (throws) `initial` is not a plain object (`null`, an
|
|
568
|
+
* array, a class instance).
|
|
569
|
+
*
|
|
570
|
+
* @capability None.
|
|
571
|
+
*
|
|
572
|
+
* @example Show a check's answer without a manual update
|
|
573
|
+
* A panel shows whether the current file has video once an asynchronous
|
|
574
|
+
* check answers. The answer is written to a tracked field; only the
|
|
575
|
+
* `bind` function that reads it runs again and sends the new value, with
|
|
576
|
+
* no `plugin.update()` and no pass over every other binding.
|
|
577
|
+
* ```ts
|
|
578
|
+
* declare const bar: Panel;
|
|
579
|
+
* declare function hasVideo(path: string): Promise<boolean>;
|
|
580
|
+
* // ---cut---
|
|
581
|
+
* const st = plugin.state({ video: null as boolean | null });
|
|
582
|
+
* bar.bind(() => ({ keyframes: st.video === true })); // reads st.video
|
|
583
|
+
* plugin.player.onChange((state) => {
|
|
584
|
+
* if (state.source === null) return;
|
|
585
|
+
* void hasVideo(state.source).then((video) => (st.video = video)); // re-runs the bind above
|
|
586
|
+
* });
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* @since 1.7.0
|
|
590
|
+
*/
|
|
591
|
+
state<T extends object>(initial: T): T;
|
|
516
592
|
}
|
|
517
593
|
/**
|
|
518
594
|
* The object the player passes to a plugin's `activate`: the root
|
|
@@ -31,6 +31,12 @@ export interface CommandState {
|
|
|
31
31
|
* `plugin.player.state` that changed (see {@link Scope.update}); only
|
|
32
32
|
* changes are sent to the player.
|
|
33
33
|
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Only a command with at least one function field takes part in the update
|
|
36
|
+
* passes (SDK 1.7.0): a command whose fields are all values or
|
|
37
|
+
* `plugin.when` conditions is registered once and evaluated again only
|
|
38
|
+
* when {@link Command.set} changes it.
|
|
39
|
+
*
|
|
34
40
|
* @example Mix a computed state with a fixed one
|
|
35
41
|
* The Loop item carries a check mark while a loop is set and is always
|
|
36
42
|
* enabled. A function is evaluated again in every full update pass (after
|
|
@@ -614,7 +620,8 @@ export interface CommandOptions {
|
|
|
614
620
|
* `busy`, `reason`) is bound: functions given to {@link Commands.add} or
|
|
615
621
|
* {@link Command.set} are evaluated again in every full update pass (after
|
|
616
622
|
* a player state change only if they read a changed field of
|
|
617
|
-
* `plugin.player.state`) and only changes reach the
|
|
623
|
+
* `plugin.player.state` or {@link Scope.state}) and only changes reach the
|
|
624
|
+
* player; a command without functions is left out of the passes. Its title, path, bindings and button cannot
|
|
618
625
|
* change in place; dispose the command (or a child {@link Scope}) and add it
|
|
619
626
|
* again. Disposing it, its scope or stopping the plugin removes the menu
|
|
620
627
|
* item, its keys and its bar button.
|
|
@@ -648,6 +655,15 @@ export interface Command extends Disposable {
|
|
|
648
655
|
/**
|
|
649
656
|
* Replace some state fields (values or functions). Last write wins.
|
|
650
657
|
*
|
|
658
|
+
* @remarks
|
|
659
|
+
* Only this command is evaluated again (SDK 1.7.0; before, `set` ran a
|
|
660
|
+
* full update pass over every binding and command of the plugin). Several
|
|
661
|
+
* calls within one microtask send one update. A function field makes the
|
|
662
|
+
* command take part in the update passes from then on. A binding that
|
|
663
|
+
* reads a plugin variable changed together with `set` outside a handler
|
|
664
|
+
* the SDK runs (a timer) is not refreshed by it: call {@link Scope.update}
|
|
665
|
+
* or keep that variable in {@link Scope.state}.
|
|
666
|
+
*
|
|
651
667
|
* @example Show a command as busy while it works
|
|
652
668
|
* The Export item shows as busy with "Exporting…" as its reason while the
|
|
653
669
|
* export runs, then returns to normal. `set` replaces only the fields it
|
|
@@ -3,9 +3,13 @@ import type { PluginInfo } from "./packages.ts";
|
|
|
3
3
|
import type { MediaCapture } from "./snapshots.ts";
|
|
4
4
|
import type { FileResolverOptions, Resolver } from "./sources.ts";
|
|
5
5
|
import type { View } from "./ui-content.ts";
|
|
6
|
+
import type { Scope, WindowState } from "./base.ts";
|
|
6
7
|
import type { Disposable, PluginError } from "./base.ts";
|
|
7
8
|
import type { Bindable } from "./commands.ts";
|
|
8
9
|
import type { Text } from "./ui-locale.ts";
|
|
10
|
+
import type { CommandKeys } from "../../commands.ts";
|
|
11
|
+
import type { SourceState } from "../../source.ts";
|
|
12
|
+
import type { PackageInfo, WindowFacts, WireTimeline, WireUpscalingState } from "../../wire.ts";
|
|
9
13
|
/**
|
|
10
14
|
* What a timeline mark stands for; readers choose colours by it.
|
|
11
15
|
*
|
|
@@ -951,7 +955,13 @@ export interface PlaybackStats {
|
|
|
951
955
|
* @category Playback
|
|
952
956
|
*/
|
|
953
957
|
export interface Player {
|
|
954
|
-
/**
|
|
958
|
+
/**
|
|
959
|
+
* Latest state; always newer than anything delivered before.
|
|
960
|
+
*
|
|
961
|
+
* With `events` the SDK follows the player's events for this copy from
|
|
962
|
+
* the plugin's start; without it the copy moves only with the start-up
|
|
963
|
+
* read and the plugin's own calls (`playback.read`).
|
|
964
|
+
*/
|
|
955
965
|
readonly state: PlayerState;
|
|
956
966
|
/**
|
|
957
967
|
* The state changed (needs `events` for outside changes).
|
|
@@ -974,6 +984,63 @@ export interface Player {
|
|
|
974
984
|
* @since 1.0.0
|
|
975
985
|
*/
|
|
976
986
|
onChange(listener: (state: PlayerState) => void): Disposable;
|
|
987
|
+
/**
|
|
988
|
+
* Listen to one event of the player, with its data as the player sent
|
|
989
|
+
* it: no state copy, no comparison.
|
|
990
|
+
*
|
|
991
|
+
* @remarks
|
|
992
|
+
* `event` is one of the {@link HostEvent} names (`"source.state"`,
|
|
993
|
+
* `"window.state"`, `"timeline.changed"`…), whatever part of the plugin
|
|
994
|
+
* API it concerns; `listener` gets a copy of that event's data, typed
|
|
995
|
+
* {@link EventPayload} (`source.state`: the player's source state, with
|
|
996
|
+
* `rate`, `paused`, `position`, `stamp`…). Each subscription counts as a
|
|
997
|
+
* listener of the plugin: the player keeps the plugin running while one
|
|
998
|
+
* exists (unless the event is one the player wakes a stopped plugin for),
|
|
999
|
+
* and its log names where the plugin added it
|
|
1000
|
+
* (`a listener added at main.ts:12`). Every name, its payload and its
|
|
1001
|
+
* capability: [Events](../../../docs/reference/events.md).
|
|
1002
|
+
*
|
|
1003
|
+
* Unlike {@link Player.onChange} it does not start the SDK's copy of the
|
|
1004
|
+
* state: `plugin.player.state` is not kept current by it, and the
|
|
1005
|
+
* listener runs for every event, changed or not. It suits pushing
|
|
1006
|
+
* values yourself (`view.set` from the listener) or reading a field the
|
|
1007
|
+
* SDK does not expose. Errors go to {@link Scope.onError}, as for every
|
|
1008
|
+
* handler; unlike the others, no full update pass follows it, so bound
|
|
1009
|
+
* values do not re-evaluate on every event: a write to a
|
|
1010
|
+
* {@link Scope.state} field re-runs only its readers, and
|
|
1011
|
+
* {@link Scope.update} re-runs everything.
|
|
1012
|
+
*
|
|
1013
|
+
* Each event needs a capability: `events` for most, `bindings.manage`
|
|
1014
|
+
* for `bindings.changed`, `commands` for `commands.keys`,
|
|
1015
|
+
* `video.upscaling` for `video.upscaling.changed`, none for
|
|
1016
|
+
* `packages.changed`. Without it the listener never runs (for `events`,
|
|
1017
|
+
* a warning in the log says so). An event an older player does not know
|
|
1018
|
+
* yet (`commands.keys`, `video.upscaling.changed`) is refused with
|
|
1019
|
+
* `unsupported`; added during `activate`, that fails the activation.
|
|
1020
|
+
*
|
|
1021
|
+
* @param event - The event's name.
|
|
1022
|
+
* @param listener - Receives each event's data.
|
|
1023
|
+
* @returns A handle that stops listening; it is disposed with the scope.
|
|
1024
|
+
*
|
|
1025
|
+
* @throws `invalid` (throws) `event` is not a {@link HostEvent} name, or
|
|
1026
|
+
* `listener` is not a function.
|
|
1027
|
+
*
|
|
1028
|
+
* @capability That of the event: `events`, or `bindings.manage`,
|
|
1029
|
+
* `commands`, `video.upscaling` for the events named above.
|
|
1030
|
+
*
|
|
1031
|
+
* @example Push the speed to a panel as it changes
|
|
1032
|
+
* A bottom panel shows the playback speed. The listener gets each
|
|
1033
|
+
* `source.state` event's data and writes the text with `set`; no update
|
|
1034
|
+
* pass runs and the SDK keeps no copy of the state for this.
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* const bar = plugin.panels.mount("bottom", "ui/bar.slint");
|
|
1037
|
+
* plugin.player.on("source.state", (s) => bar.set({ rate: `${s.rate.toFixed(2)}×` }));
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* @see [Three ways to write a plugin](../../../docs/explanation/three-ways.md)
|
|
1041
|
+
* @since 1.7.0
|
|
1042
|
+
*/
|
|
1043
|
+
on<E extends HostEvent>(event: E, listener: (data: EventPayload<E>) => void): Disposable;
|
|
977
1044
|
/**
|
|
978
1045
|
* Read the state from the player now (`playback.read`).
|
|
979
1046
|
*
|
|
@@ -1652,3 +1719,91 @@ export interface Player {
|
|
|
1652
1719
|
*/
|
|
1653
1720
|
setAudioDevice(id: string | null): Promise<void>;
|
|
1654
1721
|
}
|
|
1722
|
+
/**
|
|
1723
|
+
* The events a plugin can listen to with {@link Player.on}, by the name
|
|
1724
|
+
* the player gives them.
|
|
1725
|
+
*
|
|
1726
|
+
* @remarks
|
|
1727
|
+
* The same names the SDK subscribes to for its own copies of the player's
|
|
1728
|
+
* state (`plugin.player.state`, `plugin.window.state`,
|
|
1729
|
+
* `plugin.timeline.marks`…). {@link EventPayloads} says what each one
|
|
1730
|
+
* carries. A name outside this list is refused with `invalid`.
|
|
1731
|
+
*
|
|
1732
|
+
* @example Name the event a listener follows
|
|
1733
|
+
* A plugin logs each change of its own key labels. The name completes in
|
|
1734
|
+
* the editor, and the listener's parameter takes the type of that event's
|
|
1735
|
+
* data.
|
|
1736
|
+
* ```ts
|
|
1737
|
+
* const event: HostEvent = "commands.keys";
|
|
1738
|
+
* plugin.player.on(event, (data) => console.log("keys changed", data));
|
|
1739
|
+
* ```
|
|
1740
|
+
*
|
|
1741
|
+
* @since 1.7.0
|
|
1742
|
+
* @category Playback
|
|
1743
|
+
*/
|
|
1744
|
+
export type HostEvent = "source.state" | "playback.backend" | "window.state" | "packages.changed" | "bindings.changed" | "commands.keys" | "timeline.changed" | "appearance.changed" | "resolvers.fileTypes" | "video.upscaling.changed";
|
|
1745
|
+
/**
|
|
1746
|
+
* The data each {@link HostEvent} carries, as the player sends it: the
|
|
1747
|
+
* listener of {@link Player.on} gets a copy.
|
|
1748
|
+
*
|
|
1749
|
+
* @remarks
|
|
1750
|
+
* These are the player's wire shapes, not the SDK's views of them: field
|
|
1751
|
+
* names and units are the player's (`source.state` names the source
|
|
1752
|
+
* generation `stamp.generation`, where {@link PlayerState} says
|
|
1753
|
+
* `sourceId`). They follow the player's protocol and can gain fields with
|
|
1754
|
+
* a player version.
|
|
1755
|
+
*
|
|
1756
|
+
* @since 1.7.0
|
|
1757
|
+
* @category Playback
|
|
1758
|
+
*/
|
|
1759
|
+
export interface EventPayloads {
|
|
1760
|
+
/** The player's source: phase, position, rate, volume, its stamp (what {@link PlayerState} is made from). */
|
|
1761
|
+
"source.state": SourceState;
|
|
1762
|
+
/** A playback backend event: the backend's name for it (`event`) and the source generation it belongs to. */
|
|
1763
|
+
"playback.backend": {
|
|
1764
|
+
/** The source generation it belongs to. */
|
|
1765
|
+
currentSession: number;
|
|
1766
|
+
/** The backend's name for the event. */
|
|
1767
|
+
event: string;
|
|
1768
|
+
};
|
|
1769
|
+
/** The main window: fullscreen, maximized, video area, picture-in-picture (what {@link WindowState} is made from). */
|
|
1770
|
+
"window.state": WindowFacts;
|
|
1771
|
+
/** Every installed plugin, after an install, an uninstall or a change of one (needs no capability). */
|
|
1772
|
+
"packages.changed": PackageInfo[];
|
|
1773
|
+
/** A key binding changed somewhere; read them again with `plugin.bindings.list()`. */
|
|
1774
|
+
"bindings.changed": null;
|
|
1775
|
+
/** The key labels of this plugin's own commands, with the binding table's revision. */
|
|
1776
|
+
"commands.keys": CommandKeys;
|
|
1777
|
+
/** Every timeline mark and range, after any plugin or the player changed one. */
|
|
1778
|
+
"timeline.changed": WireTimeline;
|
|
1779
|
+
/** The palette changed (`theme`), or the interface language the user saved (`language`; the oldest players send no language). */
|
|
1780
|
+
"appearance.changed": {
|
|
1781
|
+
/** The palette now (`ThemeId`; a newer player may name one this SDK does not list). */
|
|
1782
|
+
theme: string;
|
|
1783
|
+
/** The interface language the user saved, `"system"` or a locale (absent from the oldest players). */
|
|
1784
|
+
language?: string;
|
|
1785
|
+
};
|
|
1786
|
+
/** The file extensions the plugins' file resolvers claim now. */
|
|
1787
|
+
"resolvers.fileTypes": {
|
|
1788
|
+
/** The extensions, lower case without the dot. */
|
|
1789
|
+
fileTypes: string[];
|
|
1790
|
+
};
|
|
1791
|
+
/** The AI upscaling state, without this plugin's own `enabled`. */
|
|
1792
|
+
"video.upscaling.changed": Omit<WireUpscalingState, "enabled">;
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* The data of event `E`, as the listener of {@link Player.on} gets it.
|
|
1796
|
+
*
|
|
1797
|
+
* @example Type a listener kept apart from the call
|
|
1798
|
+
* A function that handles the player's source state is written on its
|
|
1799
|
+
* own and passed to `on` later. `EventPayload` gives its parameter the
|
|
1800
|
+
* type of that event's data.
|
|
1801
|
+
* ```ts
|
|
1802
|
+
* const showRate = (s: EventPayload<"source.state">) => void plugin.osd.show("{}×", [s.rate]);
|
|
1803
|
+
* plugin.player.on("source.state", showRate);
|
|
1804
|
+
* ```
|
|
1805
|
+
*
|
|
1806
|
+
* @since 1.7.0
|
|
1807
|
+
* @category Playback
|
|
1808
|
+
*/
|
|
1809
|
+
export type EventPayload<E extends HostEvent> = EventPayloads[E];
|