@vestra-player/sdk 1.6.21 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/bin/vestra-plugin.mjs +34 -12
  3. package/dist/api-requests.d.ts +22 -0
  4. package/dist/api-requests.js +38 -0
  5. package/dist/capability-check.d.ts +48 -0
  6. package/dist/capability-check.js +219 -51
  7. package/dist/capability-rules.d.ts +21 -0
  8. package/dist/capability-rules.js +32 -1
  9. package/dist/commands.d.ts +9 -1
  10. package/dist/commands.js +8 -8
  11. package/dist/docs-tree.json.gz +0 -0
  12. package/dist/plugin/commands.js +43 -13
  13. package/dist/plugin/connection.d.ts +37 -0
  14. package/dist/plugin/connection.js +34 -0
  15. package/dist/plugin/index.js +12 -2
  16. package/dist/plugin/media.js +3 -1
  17. package/dist/plugin/packages.js +3 -1
  18. package/dist/plugin/passes.d.ts +38 -1
  19. package/dist/plugin/passes.js +89 -5
  20. package/dist/plugin/player/events.d.ts +9 -0
  21. package/dist/plugin/player/events.js +43 -0
  22. package/dist/plugin/player/rules.d.ts +7 -0
  23. package/dist/plugin/player/rules.js +11 -0
  24. package/dist/plugin/player.d.ts +37 -4
  25. package/dist/plugin/player.js +85 -12
  26. package/dist/plugin/resolvers.js +2 -3
  27. package/dist/plugin/runtime.d.ts +2 -3
  28. package/dist/plugin/runtime.js +8 -2
  29. package/dist/plugin/scope.d.ts +9 -0
  30. package/dist/plugin/scope.js +24 -0
  31. package/dist/plugin/services.js +4 -5
  32. package/dist/plugin/state.d.ts +3 -0
  33. package/dist/plugin/state.js +81 -0
  34. package/dist/plugin/stream.d.ts +27 -3
  35. package/dist/plugin/testing/commands.js +3 -3
  36. package/dist/plugin/testing/core-actions.js +1 -1
  37. package/dist/plugin/testing/services.js +1 -1
  38. package/dist/plugin/types/base.d.ts +78 -2
  39. package/dist/plugin/types/commands.d.ts +17 -1
  40. package/dist/plugin/types/playback.d.ts +156 -1
  41. package/dist/plugin/types/plugin-wire.d.ts +589 -0
  42. package/dist/plugin/types/plugin-wire.js +1 -0
  43. package/dist/plugin/types/ui-content.d.ts +23 -4
  44. package/dist/plugin/types/ui-layout.d.ts +1 -1
  45. package/dist/plugin/types/ui-shell.d.ts +4 -3
  46. package/dist/plugin/types.d.ts +4 -2
  47. package/dist/plugin/view/base.d.ts +10 -3
  48. package/dist/plugin/view/base.js +30 -6
  49. package/dist/plugin/view/binder.js +8 -1
  50. package/dist/plugin/view/writer.d.ts +49 -4
  51. package/dist/plugin/view/writer.js +383 -17
  52. package/dist/plugin/wire-facade.d.ts +4 -0
  53. package/dist/plugin/wire-facade.js +190 -0
  54. package/dist/ts-plugin.d.ts +3 -0
  55. package/dist/ts-plugin.js +18 -6
  56. package/dist/wire.d.ts +233 -20
  57. package/llms.txt +3 -3
  58. package/package.json +1 -1
  59. package/slint/vestra/focus.slint +33 -0
@@ -1,9 +1,16 @@
1
- import { memberNeeds, RULES } from "./capability-rules.js";
1
+ import { ARGUMENT_APIS } from "./api-requests.js";
2
+ import { argumentRequests, memberNeeds, requestsNeed, RULES, } from "./capability-rules.js";
2
3
  /** @internal The module plugins import the API types from. */
3
4
  export const SDK_MODULE = "@vestra-player/sdk";
4
5
  /** @internal The diagnostic code the editor shows (and its quick fix keys on). */
5
6
  export const CAPABILITY_DIAGNOSTIC = 95_301;
7
+ /**
8
+ * @internal The warning code the editor shows for a call whose capability
9
+ * the checker cannot read (`plugin.wire.request` with a computed method).
10
+ */
11
+ export const CAPABILITY_UNCHECKED = 95_302;
6
12
  const memberCache = new WeakMap();
13
+ const argumentCache = new WeakMap();
7
14
  /**
8
15
  * The module `@vestra-player/sdk` as the program resolved it: from the
9
16
  * first import or export of it in the program's own (non-declaration) files.
@@ -27,40 +34,96 @@ function sdkModule(ts, program, checker) {
27
34
  }
28
35
  return undefined;
29
36
  }
30
- /** The SDK's declarations of the members in the table. */
31
- function sdkMembers(ts, program, rules) {
32
- const cached = memberCache.get(program);
33
- if (cached && rules === RULES)
34
- return cached;
37
+ /** The SDK's declarations of the members named (`Interface.member`). */
38
+ function resolveMembers(ts, program, apis) {
35
39
  const members = new Map();
36
40
  const checker = program.getTypeChecker();
37
41
  const module = sdkModule(ts, program, checker);
38
- if (module) {
39
- const exports = new Map();
40
- for (const symbol of checker.getExportsOfModule(module))
41
- exports.set(symbol.name, symbol.flags & ts.SymbolFlags.Alias
42
- ? checker.getAliasedSymbol(symbol)
43
- : symbol);
44
- for (const api of Object.keys(rules.apis)) {
45
- const [head, ...path] = api.split(".");
46
- const root = exports.get(head);
47
- if (!root || !path.length)
48
- continue;
49
- let type = checker.getDeclaredTypeOfSymbol(root);
50
- let property;
51
- for (const name of path) {
52
- property = type?.getProperty(name);
53
- type = property && checker.getTypeOfSymbol(property);
54
- }
55
- for (const declaration of property?.declarations ?? [])
56
- if (!members.has(declaration))
57
- members.set(declaration, api);
42
+ if (!module)
43
+ return members;
44
+ const exports = new Map();
45
+ for (const symbol of checker.getExportsOfModule(module))
46
+ exports.set(symbol.name, symbol.flags & ts.SymbolFlags.Alias
47
+ ? checker.getAliasedSymbol(symbol)
48
+ : symbol);
49
+ for (const api of apis) {
50
+ const [head, ...path] = api.split(".");
51
+ const root = exports.get(head);
52
+ if (!root || !path.length)
53
+ continue;
54
+ let type = checker.getDeclaredTypeOfSymbol(root);
55
+ let property;
56
+ for (const name of path) {
57
+ property = type?.getProperty(name);
58
+ type = property && checker.getTypeOfSymbol(property);
58
59
  }
60
+ for (const declaration of property?.declarations ?? [])
61
+ if (!members.has(declaration))
62
+ members.set(declaration, api);
59
63
  }
64
+ return members;
65
+ }
66
+ /** The SDK's declarations of the members in the table. */
67
+ function sdkMembers(ts, program, rules) {
68
+ const cached = memberCache.get(program);
69
+ if (cached && rules === RULES)
70
+ return cached;
71
+ const members = resolveMembers(ts, program, Object.keys(rules.apis));
60
72
  if (rules === RULES)
61
73
  memberCache.set(program, members);
62
74
  return members;
63
75
  }
76
+ /** The SDK's declarations of the members of `ARGUMENT_APIS`. */
77
+ function argumentMembers(ts, program) {
78
+ let members = argumentCache.get(program);
79
+ if (!members) {
80
+ members = resolveMembers(ts, program, Object.keys(ARGUMENT_APIS));
81
+ argumentCache.set(program, members);
82
+ }
83
+ return members;
84
+ }
85
+ /**
86
+ * The strings an expression's type fixes: a string literal, a constant of
87
+ * one, or a union of them (the caller takes one only); `undefined` when
88
+ * the type allows any other.
89
+ */
90
+ function literalStrings(ts, checker, node) {
91
+ if (!node)
92
+ return undefined;
93
+ if (ts.isStringLiteralLike(node))
94
+ return [node.text];
95
+ const type = checker.getTypeAtLocation(node);
96
+ const parts = type.isUnion() ? type.types : [type];
97
+ const values = [];
98
+ for (const part of parts) {
99
+ if (!part.isStringLiteral())
100
+ return undefined;
101
+ values.push(part.value);
102
+ }
103
+ return values.length ? values : undefined;
104
+ }
105
+ /**
106
+ * The string fields of a request's parameters that the player's rules may
107
+ * read (`event`, `stage`): those of an object literal whose value is one
108
+ * string the types fix.
109
+ */
110
+ function stringFields(ts, checker, node) {
111
+ if (!node || !ts.isObjectLiteralExpression(node))
112
+ return undefined;
113
+ const fields = {};
114
+ for (const property of node.properties) {
115
+ if (!ts.isPropertyAssignment(property))
116
+ continue;
117
+ const name = property.name;
118
+ const key = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
119
+ ? name.text
120
+ : undefined;
121
+ const values = literalStrings(ts, checker, property.initializer);
122
+ if (key !== undefined && values?.length === 1)
123
+ fields[key] = values[0];
124
+ }
125
+ return Object.keys(fields).length ? fields : undefined;
126
+ }
64
127
  /**
65
128
  * Every use, in `options.files`, of a member whose capability the manifest
66
129
  * does not declare, in file and position order.
@@ -68,71 +131,176 @@ function sdkMembers(ts, program, rules) {
68
131
  * @internal
69
132
  */
70
133
  export function findUndeclaredCapabilities(ts, program, options) {
134
+ return checkCapabilities(ts, program, options).findings;
135
+ }
136
+ /**
137
+ * The capability check (SDK 1.7.0): the uses of members whose capability
138
+ * the manifest does not declare (`findings`, as
139
+ * {@link findUndeclaredCapabilities}), and the calls whose capability
140
+ * depends on a name the checker cannot read (`unchecked`).
141
+ *
142
+ * A call of `plugin.player.on` or `plugin.wire.on` is checked by its event
143
+ * name, one of `plugin.wire.request` by its method name and the string
144
+ * fields of its parameters (`{ event: "…" }`), when the types fix them.
145
+ *
146
+ * @internal
147
+ */
148
+ export function checkCapabilities(ts, program, options) {
71
149
  const rules = options.rules ?? RULES;
150
+ const findings = [];
151
+ const unchecked = [];
72
152
  const files = options.files
73
153
  .map((file) => program.getSourceFile(file))
74
154
  .filter((file) => !!file);
75
155
  if (!files.length)
76
- return [];
156
+ return { findings, unchecked };
77
157
  const members = sdkMembers(ts, program, rules);
78
- if (!members.size)
79
- return [];
158
+ const calls = argumentMembers(ts, program);
159
+ if (!members.size && !calls.size)
160
+ return { findings, unchecked };
80
161
  const checker = program.getTypeChecker();
81
- const findings = [];
82
- const memberOf = (symbol) => {
162
+ const apiOf = (table, symbol) => {
83
163
  for (const declaration of symbol?.declarations ?? []) {
84
- const api = members.get(declaration);
164
+ const api = table.get(declaration);
85
165
  if (api)
86
166
  return api;
87
167
  }
88
168
  return undefined;
89
169
  };
90
170
  for (const file of files) {
91
- const report = (name, symbol) => {
92
- const api = memberOf(symbol);
93
- if (!api)
94
- return;
171
+ const position = (name) => {
95
172
  const start = name.getStart(file);
96
173
  const { line, character } = file.getLineAndCharacterOfPosition(start);
97
- for (const need of memberNeeds(api, options.capabilities, rules) ?? []) {
174
+ return {
175
+ file: file.fileName,
176
+ line: line + 1,
177
+ column: character + 1,
178
+ start,
179
+ length: name.getEnd() - start,
180
+ };
181
+ };
182
+ const missing = (name, api, needs, shown = api) => {
183
+ for (const need of needs) {
98
184
  if (options.capabilities.includes(need.capability))
99
185
  continue;
100
186
  findings.push({
101
- file: file.fileName,
102
- line: line + 1,
103
- column: character + 1,
104
- start,
105
- length: name.getEnd() - start,
187
+ ...position(name),
106
188
  api,
107
189
  capability: need.capability,
108
190
  method: need.method,
109
191
  ...(need.requiredBy ? { requiredBy: need.requiredBy } : {}),
110
192
  message: need.requiredBy
111
- ? `${api} needs the capability "${need.capability}" (required by "${need.requiredBy}"), which manifest.json does not declare`
112
- : `${api} needs the capability "${need.capability}", which manifest.json does not declare`,
193
+ ? `${shown} needs the capability "${need.capability}" (required by "${need.requiredBy}"), which manifest.json does not declare`
194
+ : `${shown} needs the capability "${need.capability}", which manifest.json does not declare`,
113
195
  });
114
196
  }
115
197
  };
198
+ const report = (name, symbol) => {
199
+ const api = apiOf(members, symbol);
200
+ if (!api)
201
+ return;
202
+ missing(name, api, memberNeeds(api, options.capabilities, rules) ?? []);
203
+ };
204
+ /** A call of a member of `ARGUMENT_APIS`, by its name argument. */
205
+ const call = (node) => {
206
+ const callee = node.expression;
207
+ const name = ts.isPropertyAccessExpression(callee)
208
+ ? callee.name
209
+ : ts.isElementAccessExpression(callee) &&
210
+ ts.isStringLiteralLike(callee.argumentExpression)
211
+ ? callee.argumentExpression
212
+ : undefined;
213
+ if (!name)
214
+ return;
215
+ const api = apiOf(calls, checker.getSymbolAtLocation(name));
216
+ if (!api)
217
+ return;
218
+ const kind = ARGUMENT_APIS[api];
219
+ const values = literalStrings(ts, checker, node.arguments[0]);
220
+ // One name, or not checked: a union could be any of its names at run
221
+ // time, and none of them is known to be used.
222
+ if (values?.length !== 1) {
223
+ unchecked.push({
224
+ ...position(name),
225
+ api,
226
+ message: `${api} with ${kind === "event" ? "an event" : "a method"} name that is not one literal: its capability is not checked here (the player checks it)`,
227
+ });
228
+ return;
229
+ }
230
+ const params = kind === "method"
231
+ ? stringFields(ts, checker, node.arguments[1])
232
+ : undefined;
233
+ for (const value of values) {
234
+ const requests = argumentRequests(kind, value, params, rules);
235
+ const shown = `${api}(${JSON.stringify(value)})`;
236
+ if (!requests) {
237
+ unchecked.push({
238
+ ...position(name),
239
+ api,
240
+ message: `${shown}: the player's capability table has no such method; not checked`,
241
+ });
242
+ continue;
243
+ }
244
+ missing(name, api, requestsNeed(requests, options.capabilities, rules), shown);
245
+ }
246
+ };
247
+ /**
248
+ * A member of `ARGUMENT_APIS` taken other than by a direct call (`const
249
+ * { request } = plugin.wire`, `const on = plugin.player.on`): its calls
250
+ * cannot be followed, so it is unchecked where it is taken.
251
+ */
252
+ const taken = (name, symbol) => {
253
+ const api = apiOf(calls, symbol);
254
+ if (!api)
255
+ return;
256
+ const access = name.parent;
257
+ const parent = access?.parent;
258
+ if (access &&
259
+ (ts.isPropertyAccessExpression(access) ||
260
+ ts.isElementAccessExpression(access)) &&
261
+ parent &&
262
+ ts.isCallExpression(parent) &&
263
+ parent.expression === access)
264
+ return; // a direct call: `call` checks it
265
+ unchecked.push({
266
+ ...position(name),
267
+ api,
268
+ message: `${api} taken other than by a direct call: the calls of it are not checked here (the player checks them)`,
269
+ });
270
+ };
116
271
  const visit = (node) => {
117
- if (ts.isPropertyAccessExpression(node))
118
- report(node.name, checker.getSymbolAtLocation(node.name));
272
+ if (ts.isCallExpression(node))
273
+ call(node);
274
+ if (ts.isPropertyAccessExpression(node)) {
275
+ const symbol = checker.getSymbolAtLocation(node.name);
276
+ report(node.name, symbol);
277
+ taken(node.name, symbol);
278
+ }
119
279
  else if (ts.isElementAccessExpression(node) &&
120
- ts.isStringLiteralLike(node.argumentExpression))
121
- report(node.argumentExpression, checker.getSymbolAtLocation(node.argumentExpression));
280
+ ts.isStringLiteralLike(node.argumentExpression)) {
281
+ const symbol = checker.getSymbolAtLocation(node.argumentExpression);
282
+ report(node.argumentExpression, symbol);
283
+ taken(node.argumentExpression, symbol);
284
+ }
122
285
  else if (ts.isBindingElement(node) &&
123
286
  ts.isObjectBindingPattern(node.parent)) {
124
287
  const name = node.propertyName ?? node.name;
125
288
  const text = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
126
289
  ? name.text
127
290
  : undefined;
128
- if (text !== undefined)
129
- report(name, checker.getTypeAtLocation(node.parent).getProperty(text));
291
+ if (text !== undefined) {
292
+ const symbol = checker
293
+ .getTypeAtLocation(node.parent)
294
+ .getProperty(text);
295
+ report(name, symbol);
296
+ taken(name, symbol);
297
+ }
130
298
  }
131
299
  ts.forEachChild(node, visit);
132
300
  };
133
301
  visit(file);
134
302
  }
135
- return findings;
303
+ return { findings, unchecked };
136
304
  }
137
305
  /**
138
306
  * Whether a file belongs to the plugin's production code, given the
@@ -86,6 +86,27 @@ export interface MemberNeed {
86
86
  * @internal
87
87
  */
88
88
  export declare function memberNeeds(api: string, capabilities: readonly string[], rules?: CapabilityRules): MemberNeed[] | undefined;
89
+ /**
90
+ * The requests of a call to a member of `ARGUMENT_APIS` (SDK 1.7.0), given
91
+ * the value of its first argument and the string fields of its second:
92
+ * a subscribed event's `events.subscribe`, nothing for an event that
93
+ * arrives unasked, or the named method. `undefined`: a method the player's
94
+ * table does not know (not checked).
95
+ *
96
+ * @param kind - What the argument names (`ARGUMENT_APIS`).
97
+ * @param name - The event or method name.
98
+ * @param params - String fields of the second argument (`method` only).
99
+ *
100
+ * @internal
101
+ */
102
+ export declare function argumentRequests(kind: "event" | "method", name: string, params?: Readonly<Record<string, string>>, rules?: CapabilityRules): ApiRequest[] | undefined;
103
+ /**
104
+ * Every capability a list of requests needs with the given manifest (see
105
+ * {@link memberNeeds}).
106
+ *
107
+ * @internal
108
+ */
109
+ export declare function requestsNeed(requests: readonly ApiRequest[], capabilities: readonly string[], rules?: CapabilityRules): MemberNeed[];
89
110
  /**
90
111
  * `CAPABILITY_INFO` from the tables: the label, highlight and requirements
91
112
  * from the player's table; the members from `API_REQUESTS` (every member a
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @internal
10
10
  */
11
- import { API_REQUESTS } from "./api-requests.js";
11
+ import { API_REQUESTS, SUBSCRIBED_EVENTS } from "./api-requests.js";
12
12
  import { HOST_CAPABILITIES } from "./host-capabilities.js";
13
13
  /** @internal The SDK's rules: the synced player table and `API_REQUESTS`. */
14
14
  export const RULES = {
@@ -70,6 +70,37 @@ export function memberNeeds(api, capabilities, rules = RULES) {
70
70
  const requests = rules.apis[api];
71
71
  if (!requests)
72
72
  return undefined;
73
+ return requestsNeed(requests, capabilities, rules);
74
+ }
75
+ /**
76
+ * The requests of a call to a member of `ARGUMENT_APIS` (SDK 1.7.0), given
77
+ * the value of its first argument and the string fields of its second:
78
+ * a subscribed event's `events.subscribe`, nothing for an event that
79
+ * arrives unasked, or the named method. `undefined`: a method the player's
80
+ * table does not know (not checked).
81
+ *
82
+ * @param kind - What the argument names (`ARGUMENT_APIS`).
83
+ * @param name - The event or method name.
84
+ * @param params - String fields of the second argument (`method` only).
85
+ *
86
+ * @internal
87
+ */
88
+ export function argumentRequests(kind, name, params, rules = RULES) {
89
+ if (kind === "event")
90
+ return SUBSCRIBED_EVENTS.includes(name)
91
+ ? [{ method: "events.subscribe", params: { event: name } }]
92
+ : [];
93
+ if (!hostMethod(name, rules.host))
94
+ return undefined;
95
+ return [params ? { method: name, params } : { method: name }];
96
+ }
97
+ /**
98
+ * Every capability a list of requests needs with the given manifest (see
99
+ * {@link memberNeeds}).
100
+ *
101
+ * @internal
102
+ */
103
+ export function requestsNeed(requests, capabilities, rules = RULES) {
73
104
  // An `ifDeclared` rule is decided last, as if the plugin had declared what
74
105
  // the member's other requests need: `Player.seek` needs `playback.control`
75
106
  // for `source.submit`, and with it `source.operation` needs nothing more.
@@ -137,7 +137,7 @@ export declare const MENU_IDS: readonly ["open", "playback", "subtitles", "video
137
137
  * every icon of the player's V-Line set, `@vestra/icons.slint` (draw one
138
138
  * in your own Slint with `Icon { name: "store"; }`). The player's tests check
139
139
  * that this list is its icon set. `"sliders"` (three sliders, the player's
140
- * Adjust button) is new in player 0.7.6 (SDK 1.6.11); older players refuse
140
+ * Adjustments and Effects button) is new in player 0.7.6 (SDK 1.6.11); older players refuse
141
141
  * it as a button icon with `invalid`.
142
142
  *
143
143
  * @example Check in a test that the button's icon exists
@@ -351,8 +351,16 @@ export type CommandDeclaration = {
351
351
  * local id, and (SDK 1.6.16) each of the player's own as `host/<id>`, with
352
352
  * the labels of its current keys; the answer to the request and the data of
353
353
  * the event of that name.
354
+ *
355
+ * @remarks
356
+ * The player's wire shape (`commands.keys`), part of the protocol, which is not
357
+ * semver: it can gain fields with a player version.
358
+ *
359
+ * @since 1.7.0
360
+ * @category Playback
354
361
  */
355
362
  export type CommandKeys = {
363
+ /** The key labels of each command, by local id (the player's own: `host/<id>`). */
356
364
  keys: Record<string, string[]>;
357
365
  /** The player's binding table revision: a larger one is newer. */
358
366
  revision: number;
package/dist/commands.js CHANGED
@@ -142,7 +142,7 @@ export const MENU_IDS = [
142
142
  * every icon of the player's V-Line set, `@vestra/icons.slint` (draw one
143
143
  * in your own Slint with `Icon { name: "store"; }`). The player's tests check
144
144
  * that this list is its icon set. `"sliders"` (three sliders, the player's
145
- * Adjust button) is new in player 0.7.6 (SDK 1.6.11); older players refuse
145
+ * Adjustments and Effects button) is new in player 0.7.6 (SDK 1.6.11); older players refuse
146
146
  * it as a button icon with `invalid`.
147
147
  *
148
148
  * @example Check in a test that the button's icon exists
@@ -287,11 +287,8 @@ vestra.capture | capture.copy | Snapshot ▸ Copy Current Frame | Ctrl+C
287
287
  vestra.capture | capture.burst | Snapshot ▸ Burst… | Ctrl+G
288
288
  vestra.capture | capture.clip | Snapshot ▸ Export Clip…
289
289
  vestra.capture | capture.panel | Snapshot ▸ Capture… | Alt+S
290
- vestra.video | video.picture | Picture… | Alt+1
291
- vestra.audio | audio.workbench | Audio… | Alt+2
292
- vestra.subtitles | tune | Subtitles… | Alt+3
293
- vestra.playback | panel | Playback… | Alt+4
294
- vestra.playlist | playlist.visibility | Playlist | F6
290
+ host | adjust | Adjustments and Effects
291
+ host | sidebar | Sidebar
295
292
  vestra.marks | marks.list | Chapter and Bookmark List… | H
296
293
  host | fullscreen | Toggle Fullscreen | Escape
297
294
  vestra.workshop | workshop.open | Vestra Player AI…
@@ -304,8 +301,6 @@ host | previous | (Previous) | PageUp, Mouse:X2
304
301
  host | next | (Next) | PageDown, Mouse:X1
305
302
  host | enter-fullscreen | (Enter Fullscreen)
306
303
  host | exit-fullscreen | (Leave Fullscreen)
307
- host | sidebar | (Toggle Sidebar)
308
- host | adjust | (Adjust)
309
304
  host | volume-up | (Volume +) | ArrowUp, Mouse:WheelUp
310
305
  host | volume-down | (Volume −) | ArrowDown, Mouse:WheelDown
311
306
  host | mute | (Mute) | M
@@ -316,6 +311,11 @@ host | seek-forward | (Forward 5 s) | ArrowRight
316
311
  host | rate-normal | (Normal) | Z
317
312
  host | rate-down | (Slower 0.1) | X
318
313
  host | rate-up | (Faster 0.1) | C
314
+ vestra.video | video.picture | (Picture…) | Alt+1
315
+ vestra.audio | audio.workbench | (Audio…) | Alt+2
316
+ vestra.subtitles | tune | (Subtitles…) | Alt+3
317
+ vestra.playback | panel | (Playback…) | Alt+4
318
+ vestra.playlist | playlist.visibility | (Playlist) | F6
319
319
  vestra.playback | reopen | (Reopen Current/Last File) | Ctrl+Y
320
320
  vestra.playback | copy-name | (File Name)
321
321
  vestra.playback | copy-folder | (Folder Path)
Binary file
@@ -7,6 +7,11 @@ import { ImageHandle } from "./view/image.js";
7
7
  import { isTextValue, textProblem } from "../i18n.js";
8
8
  import { conditionJson, isCondition } from "./when.js";
9
9
  const value = (item) => typeof item === "function" ? item() : item;
10
+ /**
11
+ * A state field given as a function: the command is evaluated in the update
12
+ * passes. Constants and `plugin.when` conditions are not (SDK 1.7.0).
13
+ */
14
+ const tracks = (spec) => Object.values(spec).some((field) => typeof field === "function");
10
15
  /** A field's value, or `fallback` (and its condition noted) for a condition. */
11
16
  function field(item, fallback, name, when) {
12
17
  if (!isCondition(item))
@@ -97,14 +102,6 @@ function button(id, value, inMenu) {
97
102
  throw fail(`unknown button icon ${JSON.stringify(icon)}: a name of @vestra/icons.slint (BAR_BUTTON_ICONS) or an image from plugin.ui.image`);
98
103
  return { icon, order };
99
104
  }
100
- /** Unregistrations in flight per plugin: re-adding an id waits for its removal. */
101
- const removals = new WeakMap();
102
- const removing = (runtime) => {
103
- let map = removals.get(runtime);
104
- if (!map)
105
- removals.set(runtime, (map = new Map()));
106
- return map;
107
- };
108
105
  class CommandHandle {
109
106
  id;
110
107
  ready;
@@ -122,7 +119,15 @@ class CommandHandle {
122
119
  #label;
123
120
  /** Where the plugin added it, for the player's log. */
124
121
  #where;
122
+ /**
123
+ * Its place in the update passes: only while a state field is a function
124
+ * (`tracks`); a command of constants is registered and left alone.
125
+ */
125
126
  #binding;
127
+ /** A `set()` of a command outside the passes is sent in a microtask. */
128
+ #queued = false;
129
+ /** Its place in the order of evaluation, should it bind later. */
130
+ #slot;
126
131
  constructor(scope, options) {
127
132
  const runtime = scope.runtime;
128
133
  this.#where = runtime.callSite();
@@ -140,7 +145,7 @@ class CommandHandle {
140
145
  const declaration = declare(options);
141
146
  // The host requires a strictly increasing revision per update; the
142
147
  // registration itself is revision 1, so every later state follows it.
143
- const previous = removing(runtime).get(this.id);
148
+ const previous = runtime.removals.get(this.id);
144
149
  this.#pump = new Latest(async ({ state, when }) => {
145
150
  if (this.#refused)
146
151
  return;
@@ -171,7 +176,9 @@ class CommandHandle {
171
176
  scope.run(options.run);
172
177
  };
173
178
  runtime.commands.set(this.id, this.#run);
174
- this.#binding = runtime.bind(() => this.#sync());
179
+ this.#slot = runtime.passes.slot();
180
+ if (tracks(this.#spec))
181
+ this.#binding = runtime.bind(() => this.#sync(), this.#slot);
175
182
  scope.add(this);
176
183
  }
177
184
  /**
@@ -215,9 +222,32 @@ class CommandHandle {
215
222
  this.#last = encoded;
216
223
  this.#pump.push(state).catch((error) => this.#scope.report(error));
217
224
  }
225
+ /**
226
+ * This command's state alone (SDK 1.7.0; before, a full update pass): a
227
+ * bound command is evaluated in the next pass, a command of constants
228
+ * sends its new state through its own `Latest` in a microtask (several
229
+ * `set()` calls in one turn send one update). A function field binds it.
230
+ */
218
231
  set(state) {
219
232
  Object.assign(this.#spec, state);
220
- this.#scope.update();
233
+ if (this.#disposed)
234
+ return;
235
+ if (!this.#binding && tracks(this.#spec))
236
+ this.#binding = this.#scope.runtime.bind(() => this.#sync(), this.#slot);
237
+ if (this.#binding)
238
+ return this.#binding.invalidate();
239
+ if (this.#queued)
240
+ return;
241
+ this.#queued = true;
242
+ queueMicrotask(() => {
243
+ this.#queued = false;
244
+ try {
245
+ this.#sync();
246
+ }
247
+ catch (error) {
248
+ this.#scope.report(error);
249
+ }
250
+ });
221
251
  }
222
252
  async dispose() {
223
253
  if (this.#disposed)
@@ -230,9 +260,9 @@ class CommandHandle {
230
260
  this.#pump.stop();
231
261
  // Removed from the menu once registered. Recorded before any await, so an
232
262
  // immediate re-add of the same id registers after this removal.
233
- const pending = removing(runtime);
263
+ const pending = runtime.removals;
234
264
  const removal = (async () => {
235
- await this.#binding.dispose();
265
+ await this.#binding?.dispose();
236
266
  await this.ready.catch(() => { });
237
267
  if (this.#registered)
238
268
  await runtime.host.commands.unregister(this.id).catch(() => { });
@@ -28,6 +28,20 @@ export interface RuntimeOptions {
28
28
  /** A stop reason the runner passed on, if this SDK knows it. */
29
29
  export declare function stopReason(value: unknown): StopReason | undefined;
30
30
  type Listener = (data: unknown) => void;
31
+ /**
32
+ * How primitives tell the framework above them about plugin-visible state
33
+ * they changed or read, without importing it (refactor plan §2.1: L1 never
34
+ * imports the passes). `Runtime` installs the update passes here; on a
35
+ * bare connection every call does nothing.
36
+ */
37
+ export interface StateSignals {
38
+ /** `key`'s `field` (without one: all of it) is read by what is evaluated now. */
39
+ read(key: string, field?: string): void;
40
+ /** Fields of `key` changed: what read them is evaluated again. */
41
+ changed(key: string, fields: Iterable<string>): void;
42
+ /** Something the plugin sees changed that no key describes: everything is evaluated again. */
43
+ invalidate(): void;
44
+ }
31
45
  /**
32
46
  * Per-plugin connection to the player. Scopes reach it through `Runtime`;
33
47
  * the flat RPC clients stay private here so protocol fields never reach
@@ -46,7 +60,21 @@ export declare class Connection {
46
60
  readonly startup: Set<Promise<unknown>>;
47
61
  readonly views: Map<string, (callback: string, args: Json[]) => void>;
48
62
  readonly commands: Map<string, () => void>;
63
+ /**
64
+ * Command unregistrations in flight, by id: a command registered again
65
+ * with the id (`commands.add` or `plugin.wire.commands.register`) waits
66
+ * for its removal, or the player would refuse it with `conflict`.
67
+ */
68
+ readonly removals: Map<string, Promise<void>>;
49
69
  readonly services: Map<string, unknown>;
70
+ /**
71
+ * How to read a state copy again, by the event that keeps it current: a
72
+ * mirror registers itself (`source.state` → the player's), an action that
73
+ * changed that state elsewhere asks for it (`reread`).
74
+ */
75
+ readonly rereads: Map<string, () => Promise<unknown>>;
76
+ /** The framework's ears ({@link StateSignals}); silent until `Runtime` sets them. */
77
+ signals: StateSignals;
50
78
  /**
51
79
  * Set when the player stops the plugin (`PluginInstance.dispose`), before
52
80
  * the root scope is disposed: `DisposeInfo` and `plugin.stopReason`.
@@ -66,6 +94,8 @@ export declare class Connection {
66
94
  readonly features: ReadonlySet<string>;
67
95
  constructor(transport: Transport, manifest: PluginManifest, directory: string, dataDirectory?: string, app?: unknown, options?: RuntimeOptions);
68
96
  can(capability: string): boolean;
97
+ /** Read the state copy kept by `event` again, if one exists; never rejects. */
98
+ reread(event: string): Promise<void>;
69
99
  /** Lazily created singletons shared by every scope of this plugin. */
70
100
  service<T>(name: string, create: () => T): T;
71
101
  /**
@@ -111,6 +141,13 @@ export declare class Connection {
111
141
  * `vestra-plugin test`.
112
142
  */
113
143
  listening(): Map<string, string[]>;
144
+ /**
145
+ * One request by its method name, as given (`plugin.wire.request`, SDK
146
+ * 1.7.0): nothing added, nothing checked here, the player checks the
147
+ * capability. Every other part of the SDK uses the typed clients
148
+ * (`host`); `scripts/check-layers.mjs` keeps it so.
149
+ */
150
+ request<T>(method: string, params?: Json): Promise<T>;
114
151
  /** Raw transport events the host pushes without a subscription. */
115
152
  raw(event: string, listener: Listener): Disposable;
116
153
  }