@sirenodeck/sirenodeck 0.1.1-alpha.0 → 0.2.2
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/LICENSE +674 -21
- package/bin/dev.js +12 -2
- package/dist/main.mjs +3655 -1657
- package/package.json +18 -16
- package/src/api/protocol-internal.ts +16 -1
- package/src/assets/logo.png +0 -0
- package/src/assets/logo72x72.png +0 -0
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +12 -2
- package/src/builtin-addons/coding-agents/buttons/agent/config.ts +5 -1
- package/src/builtin-addons/coding-agents/buttons/summary/config.ts +15 -3
- package/src/builtin-addons/coding-agents/buttons/summary/frontend.tsx +3 -3
- package/src/builtin-addons/coding-agents/global/backend.ts +56 -34
- package/src/builtin-addons/coding-agents/providers/opencode.ts +4 -5
- package/src/builtin-addons/core/buttons/action/config.ts +5 -2
- package/src/builtin-addons/core/buttons/change-deck/config.ts +6 -3
- package/src/builtin-addons/core/buttons/media-sample/config.ts +2 -2
- package/src/builtin-addons/core/buttons/toggle/config.ts +26 -9
- package/src/builtin-addons/date-time/buttons/custom/config.ts +5 -1
- package/src/builtin-addons/date-time/buttons/date/config.ts +2 -2
- package/src/builtin-addons/date-time/buttons/time/config.ts +5 -1
- package/src/builtin-addons/emoji-selector/buttons/category/config.ts +3 -3
- package/src/builtin-addons/emoji-selector/buttons/emoji/config.ts +5 -2
- package/src/builtin-addons/emoji-selector/support.ts +5 -2
- package/src/builtin-addons/global-services.ts +23 -0
- package/src/builtin-addons/internal-settings/buttons/app-info/config.ts +2 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-down/config.ts +6 -1
- package/src/builtin-addons/internal-settings/buttons/brightness-up/config.ts +6 -1
- package/src/builtin-addons/media/backend.ts +54 -0
- package/src/builtin-addons/media/buttons/volume/volume-down/config.ts +1 -1
- package/src/builtin-addons/media/buttons/volume/volume-up/config.ts +1 -1
- package/src/builtin-addons/session/buttons/time/config.ts +1 -1
- package/src/builtin-addons/system-status/buttons/system-status/schemas.ts +32 -6
- package/src/builtin-addons/system-status/manifest.ts +49 -0
- package/src/builtin-addons/value-display/buttons/value-display/config.ts +23 -9
- package/src/builtin-addons/weather/buttons/weather/config.ts +11 -6
- package/src/cli/coding-agents-onboarding.ts +181 -34
- package/src/cli/commands/command-executor.ts +61 -0
- package/src/cli/commands/emulator-mode.ts +17 -2
- package/src/cli/commands/network-bind.ts +13 -9
- package/src/cli/commands/restart.ts +15 -5
- package/src/cli/commands/run.ts +174 -317
- package/src/cli/commands/service/render-template.ts +10 -0
- package/src/cli/commands/skills.ts +106 -0
- package/src/cli/commands/start.ts +39 -9
- package/src/cli/commands/stop.ts +3 -2
- package/src/cli/commands/system-requirements.ts +1 -0
- package/src/cli/index.ts +16 -3
- package/src/cli/main.ts +15 -2
- package/src/cli/package-manager.ts +6 -0
- package/src/cli/skills-first-run.ts +46 -0
- package/src/cli/startup-display.ts +35 -17
- package/src/config/mutation.ts +13 -1
- package/src/config/schemas.ts +3 -3
- package/src/config/validation.ts +7 -1
- package/src/core/icon-asset-registry.ts +11 -6
- package/src/deck/addon-handler-bridge.ts +246 -176
- package/src/deck/deck-config.ts +11 -2
- package/src/deck/deck-presentation-publisher.ts +116 -0
- package/src/deck/index.ts +13 -0
- package/src/deck/inject-config-ui-button.ts +23 -0
- package/src/deck/methods.ts +23 -0
- package/src/deck/position-settings-version-button.ts +20 -0
- package/src/deck/runtime/host-policy-coordinator.ts +186 -0
- package/src/deck/runtime/runtime.ts +123 -250
- package/src/deck/system-back-injection.ts +2 -1
- package/src/device/reconnecting.ts +8 -1
- package/src/index.ts +1 -2
- package/src/outputClient/emulator.ts +13 -0
- package/src/outputClient/index.ts +8 -0
- package/src/outputClient/real.ts +40 -45
- package/src/outputClient/remote-mirror.ts +77 -0
- package/src/outputClient/types.ts +2 -0
- package/src/render/editor-handler.ts +12 -1
- package/src/render/frontend-bridge-url.ts +10 -0
- package/src/render/push-startup-screen.ts +76 -0
- package/src/render/ws-bridge.ts +2 -0
- package/src/system/providers/active-app/capture-file.ts +61 -0
- package/src/system/providers/active-app/wayland-gnome.ts +26 -10
- package/src/system/providers/active-app.ts +6 -0
- package/src/system/providers/clipboard/darwin.ts +28 -4
- package/src/system/providers/url.ts +57 -0
- package/src/util/logger.ts +19 -3
- package/src/version.ts +3 -1
- package/src/vite/virtual-modules.ts +12 -6
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
} from "@/addon/api"
|
|
13
13
|
import type { ScannedAddon } from "@/cli/commands/addon-registry"
|
|
14
14
|
import { BUILTIN_MANIFESTS } from "@/builtin-addons/register-builtins"
|
|
15
|
+
import { BUILTIN_GLOBAL_SERVICES } from "@/builtin-addons/global-services"
|
|
15
16
|
import type { PubSub } from "@/core/pub-sub"
|
|
16
17
|
import type { Store } from "@/core/store"
|
|
17
18
|
import type { Methods } from "@/deck/methods"
|
|
@@ -62,7 +63,31 @@ const staticAddonModule = (addonName: string): AddonModule | null => {
|
|
|
62
63
|
return manifest === undefined ? null : ({ manifest } as AddonModule)
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The module carrying a builtin's global service, without touching the disk.
|
|
68
|
+
*
|
|
69
|
+
* ponytail: taking the manifest for this unconditionally was wrong and broke
|
|
70
|
+
* `coding-agents`, whose manifest mentions `globalService` only in a comment —
|
|
71
|
+
* the service itself lives in `global-entry.ts`. The bridge found no service on
|
|
72
|
+
* the manifest, skipped the addon, and never fell back to the import, so the
|
|
73
|
+
* agents deck and summary button went empty and the persisted snapshot stopped
|
|
74
|
+
* being refreshed. Only stand in for the import when there is genuinely a
|
|
75
|
+
* service to hand over.
|
|
76
|
+
*/
|
|
77
|
+
const staticGlobalServiceModule = (addonName: string): AddonModule | null => {
|
|
78
|
+
const direct = BUILTIN_GLOBAL_SERVICES.get(addonName)
|
|
79
|
+
if (direct !== undefined)
|
|
80
|
+
return { globalService: direct } as unknown as AddonModule
|
|
81
|
+
const fromManifest = staticAddonModule(addonName)
|
|
82
|
+
if (fromManifest === null) return null
|
|
83
|
+
const manifest = fromManifest.manifest as
|
|
84
|
+
| { globalService?: unknown }
|
|
85
|
+
| undefined
|
|
86
|
+
return manifest?.globalService === undefined ? null : fromManifest
|
|
87
|
+
}
|
|
88
|
+
|
|
65
89
|
export interface AddonBridgeHandle {
|
|
90
|
+
reconcile(decks: ReadonlyArray<RuntimeDeck>): Promise<void>
|
|
66
91
|
dispose(): void
|
|
67
92
|
}
|
|
68
93
|
|
|
@@ -114,7 +139,7 @@ export const bridgeAddonServices = async (
|
|
|
114
139
|
|
|
115
140
|
try {
|
|
116
141
|
const mod =
|
|
117
|
-
|
|
142
|
+
staticGlobalServiceModule(addon.name) ??
|
|
118
143
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
144
|
((await import(addon.globalServiceEntry)) as AddonModule)
|
|
120
145
|
let globalService: AddonGlobalService | undefined
|
|
@@ -249,190 +274,227 @@ export const bridgeAddonServices = async (
|
|
|
249
274
|
const deckButtonCleanup = new Map<
|
|
250
275
|
string,
|
|
251
276
|
Array<{
|
|
277
|
+
handlerId: string
|
|
252
278
|
buttonAbort: AbortController
|
|
253
279
|
buttonService: AddonButtonService
|
|
254
280
|
wrappedCtx: AddonButtonServiceContext<unknown>
|
|
255
281
|
}>
|
|
256
282
|
>()
|
|
283
|
+
const mountedButtonSignatures = new Map<string, string>()
|
|
284
|
+
|
|
285
|
+
const mountButtons = async (
|
|
286
|
+
nextDecks: ReadonlyArray<RuntimeDeck>,
|
|
287
|
+
): Promise<void> => {
|
|
288
|
+
for (const deck of nextDecks) {
|
|
289
|
+
for (const button of deck.buttons) {
|
|
290
|
+
const buttonType = button.type
|
|
291
|
+
|
|
292
|
+
let addonName: string | null = null
|
|
293
|
+
let resolvedButtonType: string | null = null
|
|
294
|
+
for (const addon of allAddons) {
|
|
295
|
+
if (addon.types.includes(buttonType)) {
|
|
296
|
+
addonName = addon.name
|
|
297
|
+
resolvedButtonType = buttonType
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
if (
|
|
301
|
+
typeof addon.defaultButton === "string" &&
|
|
302
|
+
addon.name === buttonType
|
|
303
|
+
) {
|
|
304
|
+
addonName = addon.name
|
|
305
|
+
resolvedButtonType = addon.defaultButton
|
|
306
|
+
break
|
|
307
|
+
}
|
|
308
|
+
}
|
|
257
309
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
310
|
+
if (addonName === null || resolvedButtonType === null) continue
|
|
311
|
+
const handlerId = `${deck.id}:${button.id}`
|
|
312
|
+
const signature = JSON.stringify([
|
|
313
|
+
button.type,
|
|
314
|
+
button.config ?? null,
|
|
315
|
+
button.position ?? null,
|
|
316
|
+
])
|
|
317
|
+
if (mountedButtonSignatures.get(handlerId) === signature) continue
|
|
318
|
+
|
|
319
|
+
const globalMethods = addonMethods.get(addonName) ?? {}
|
|
320
|
+
const buttonMethods: Record<string, AddonServiceMethod> = {}
|
|
321
|
+
for (const [methodName, method] of Object.entries(globalMethods)) {
|
|
322
|
+
buttonMethods[namespacedKey(addonName, methodName)] = method
|
|
269
323
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
324
|
+
|
|
325
|
+
let addonMod: AddonModule | null = null
|
|
326
|
+
for (const addon of allAddons) {
|
|
327
|
+
if (addon.name !== addonName) continue
|
|
328
|
+
if (addon.frontendEntry === null) continue
|
|
329
|
+
try {
|
|
330
|
+
addonMod =
|
|
331
|
+
staticAddonModule(addon.name) ??
|
|
332
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
333
|
+
((await import(addon.frontendEntry)) as AddonModule)
|
|
334
|
+
} catch (err) {
|
|
335
|
+
// ponytail: silence here meant a failed import surfaced only as a
|
|
336
|
+
// button that ignored taps. See the matching catch above.
|
|
337
|
+
logger.error(
|
|
338
|
+
{ addonName, entry: addon.frontendEntry, err },
|
|
339
|
+
"addon button handlers failed to load",
|
|
340
|
+
)
|
|
341
|
+
}
|
|
276
342
|
break
|
|
277
343
|
}
|
|
278
|
-
}
|
|
279
344
|
|
|
280
|
-
|
|
345
|
+
const exported = addonMod
|
|
346
|
+
? (addonMod.manifest ??
|
|
347
|
+
(addonMod.default && typeof addonMod.default === "object"
|
|
348
|
+
? addonMod.default
|
|
349
|
+
: null))
|
|
350
|
+
: null
|
|
281
351
|
|
|
282
|
-
|
|
283
|
-
const buttonMethods: Record<string, AddonServiceMethod> = {}
|
|
284
|
-
for (const [methodName, method] of Object.entries(globalMethods)) {
|
|
285
|
-
buttonMethods[namespacedKey(addonName, methodName)] = method
|
|
286
|
-
}
|
|
352
|
+
if (exported === null) continue
|
|
287
353
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
((await import(addon.frontendEntry)) as AddonModule)
|
|
297
|
-
} catch (err) {
|
|
298
|
-
// ponytail: silence here meant a failed import surfaced only as a
|
|
299
|
-
// button that ignored taps. See the matching catch above.
|
|
300
|
-
logger.error(
|
|
301
|
-
{ addonName, entry: addon.frontendEntry, err },
|
|
302
|
-
"addon button handlers failed to load",
|
|
303
|
-
)
|
|
354
|
+
const manifest = exported as {
|
|
355
|
+
readonly name?: string
|
|
356
|
+
readonly buttonTypes?: Record<
|
|
357
|
+
string,
|
|
358
|
+
{
|
|
359
|
+
readonly service?: AddonButtonTypeService & AddonButtonService
|
|
360
|
+
}
|
|
361
|
+
>
|
|
304
362
|
}
|
|
305
|
-
break
|
|
306
|
-
}
|
|
307
363
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
(addonMod.default && typeof addonMod.default === "object"
|
|
311
|
-
? addonMod.default
|
|
312
|
-
: null))
|
|
313
|
-
: null
|
|
314
|
-
|
|
315
|
-
if (exported === null) continue
|
|
316
|
-
|
|
317
|
-
const manifest = exported as {
|
|
318
|
-
readonly name?: string
|
|
319
|
-
readonly buttonTypes?: Record<
|
|
320
|
-
string,
|
|
321
|
-
{
|
|
322
|
-
readonly service?: AddonButtonTypeService & AddonButtonService
|
|
323
|
-
}
|
|
324
|
-
>
|
|
325
|
-
}
|
|
364
|
+
const buttonTypeEntry = manifest.buttonTypes?.[resolvedButtonType]
|
|
365
|
+
if (buttonTypeEntry?.service === undefined) continue
|
|
326
366
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
367
|
+
const buttonService = buttonTypeEntry.service
|
|
368
|
+
const buttonCtx: AddonButtonServiceContext<unknown> = {
|
|
369
|
+
config: button.config ?? {},
|
|
370
|
+
buttonId: button.id,
|
|
371
|
+
...(button.position !== undefined
|
|
372
|
+
? { position: button.position }
|
|
373
|
+
: {}),
|
|
374
|
+
addonName,
|
|
375
|
+
methods: Object.freeze(buttonMethods),
|
|
376
|
+
coreMethods: methods,
|
|
377
|
+
publish: (channel: string, data: unknown) =>
|
|
378
|
+
pubSub.publish(channel, data),
|
|
379
|
+
executor,
|
|
380
|
+
signal: abortController.signal,
|
|
381
|
+
store,
|
|
382
|
+
}
|
|
344
383
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
384
|
+
const buttonAbort = new AbortController()
|
|
385
|
+
abortController.signal.addEventListener("abort", () =>
|
|
386
|
+
buttonAbort.abort(),
|
|
387
|
+
)
|
|
349
388
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
389
|
+
const wrappedCtx = {
|
|
390
|
+
...buttonCtx,
|
|
391
|
+
signal: buttonAbort.signal,
|
|
392
|
+
}
|
|
354
393
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
394
|
+
const existing = deckButtonCleanup.get(deck.id) ?? []
|
|
395
|
+
existing.push({ handlerId, buttonAbort, buttonService, wrappedCtx })
|
|
396
|
+
deckButtonCleanup.set(deck.id, existing)
|
|
358
397
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
398
|
+
try {
|
|
399
|
+
buttonService.onMount?.(wrappedCtx)
|
|
400
|
+
} catch (err) {
|
|
401
|
+
logger.error({ addonName, buttonType, err }, `addon onMount threw`)
|
|
402
|
+
}
|
|
364
403
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
)
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
} catch (err) {
|
|
426
|
-
logger.error({ addonName, buttonType, err }, `addon dispose failed`)
|
|
427
|
-
}
|
|
428
|
-
},
|
|
404
|
+
const allowedGestures = buttonService.gestureHandlers
|
|
405
|
+
const handler = {
|
|
406
|
+
...(allowedGestures?.includes("tap") && buttonService.onTap
|
|
407
|
+
? {
|
|
408
|
+
async onTap() {
|
|
409
|
+
try {
|
|
410
|
+
await buttonService.onTap?.(wrappedCtx)
|
|
411
|
+
} catch (err) {
|
|
412
|
+
logger.error(
|
|
413
|
+
{ addonName, buttonType: resolvedButtonType, err },
|
|
414
|
+
`addon onTap failed`,
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
}
|
|
419
|
+
: {}),
|
|
420
|
+
...(allowedGestures?.includes("dbl-tap") && buttonService.onDblTap
|
|
421
|
+
? {
|
|
422
|
+
async onDblTap() {
|
|
423
|
+
try {
|
|
424
|
+
await buttonService.onDblTap?.(wrappedCtx)
|
|
425
|
+
} catch (err) {
|
|
426
|
+
logger.error(
|
|
427
|
+
{ addonName, buttonType: resolvedButtonType, err },
|
|
428
|
+
`addon onDblTap failed`,
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
}
|
|
433
|
+
: {}),
|
|
434
|
+
...(allowedGestures?.includes("hold") && buttonService.onHold
|
|
435
|
+
? {
|
|
436
|
+
async onHold() {
|
|
437
|
+
try {
|
|
438
|
+
await buttonService.onHold?.(wrappedCtx)
|
|
439
|
+
} catch (err) {
|
|
440
|
+
logger.error(
|
|
441
|
+
{ addonName, buttonType: resolvedButtonType, err },
|
|
442
|
+
`addon onHold failed`,
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
}
|
|
447
|
+
: {}),
|
|
448
|
+
dispose() {
|
|
449
|
+
buttonAbort.abort()
|
|
450
|
+
try {
|
|
451
|
+
buttonService.dispose?.(wrappedCtx)
|
|
452
|
+
} catch (err) {
|
|
453
|
+
logger.error(
|
|
454
|
+
{ addonName, buttonType, err },
|
|
455
|
+
`addon dispose failed`,
|
|
456
|
+
)
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
runtime.registerButtonHandler(handlerId, handler)
|
|
462
|
+
registeredHandlerIds.add(handlerId)
|
|
463
|
+
mountedButtonSignatures.set(handlerId, signature)
|
|
429
464
|
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
430
467
|
|
|
431
|
-
|
|
432
|
-
|
|
468
|
+
await mountButtons(decks)
|
|
469
|
+
|
|
470
|
+
const unmountHandler = (handlerId: string): void => {
|
|
471
|
+
runtime.unregisterButtonHandler(handlerId)
|
|
472
|
+
registeredHandlerIds.delete(handlerId)
|
|
473
|
+
mountedButtonSignatures.delete(handlerId)
|
|
474
|
+
for (const [deckId, tracked] of deckButtonCleanup) {
|
|
475
|
+
const remaining = []
|
|
476
|
+
for (const entry of tracked) {
|
|
477
|
+
if (entry.handlerId !== handlerId) {
|
|
478
|
+
remaining.push(entry)
|
|
479
|
+
continue
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
entry.buttonService.onUnmount?.(entry.wrappedCtx)
|
|
483
|
+
} catch (err) {
|
|
484
|
+
logger.error({ err }, "bridge onUnmount failed")
|
|
485
|
+
}
|
|
486
|
+
entry.buttonAbort.abort()
|
|
487
|
+
}
|
|
488
|
+
if (remaining.length === 0) deckButtonCleanup.delete(deckId)
|
|
489
|
+
else deckButtonCleanup.set(deckId, remaining)
|
|
433
490
|
}
|
|
434
491
|
}
|
|
435
492
|
|
|
493
|
+
const unmountButtons = (): void => {
|
|
494
|
+
for (const handlerId of [...registeredHandlerIds]) unmountHandler(handlerId)
|
|
495
|
+
deckButtonCleanup.clear()
|
|
496
|
+
}
|
|
497
|
+
|
|
436
498
|
const unsubscribeDeckInactive = pubSub.subscribe(
|
|
437
499
|
"runtime:deck-inactive",
|
|
438
500
|
(payload: unknown) => {
|
|
@@ -480,21 +542,7 @@ export const bridgeAddonServices = async (
|
|
|
480
542
|
if (disposed) return
|
|
481
543
|
disposed = true
|
|
482
544
|
for (const cleanup of trackedCleanup) cleanup()
|
|
483
|
-
|
|
484
|
-
runtime.unregisterButtonHandler(handlerId)
|
|
485
|
-
}
|
|
486
|
-
registeredHandlerIds.clear()
|
|
487
|
-
for (const tracked of deckButtonCleanup.values()) {
|
|
488
|
-
for (const { buttonAbort, buttonService, wrappedCtx } of tracked) {
|
|
489
|
-
try {
|
|
490
|
-
buttonService.onUnmount?.(wrappedCtx)
|
|
491
|
-
} catch (err) {
|
|
492
|
-
logger.error({ err }, `bridge onUnmount failed`)
|
|
493
|
-
}
|
|
494
|
-
buttonAbort.abort()
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
deckButtonCleanup.clear()
|
|
545
|
+
unmountButtons()
|
|
498
546
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
499
547
|
try {
|
|
500
548
|
const ctx: AddonServiceContext = {
|
|
@@ -512,5 +560,27 @@ export const bridgeAddonServices = async (
|
|
|
512
560
|
abortController.abort()
|
|
513
561
|
}
|
|
514
562
|
|
|
515
|
-
return {
|
|
563
|
+
return {
|
|
564
|
+
reconcile: async (nextDecks) => {
|
|
565
|
+
const nextSignatures = new Map<string, string>()
|
|
566
|
+
for (const deck of nextDecks) {
|
|
567
|
+
for (const button of deck.buttons) {
|
|
568
|
+
nextSignatures.set(
|
|
569
|
+
`${deck.id}:${button.id}`,
|
|
570
|
+
JSON.stringify([
|
|
571
|
+
button.type,
|
|
572
|
+
button.config ?? null,
|
|
573
|
+
button.position ?? null,
|
|
574
|
+
]),
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
for (const [handlerId, signature] of mountedButtonSignatures) {
|
|
579
|
+
if (nextSignatures.get(handlerId) !== signature)
|
|
580
|
+
unmountHandler(handlerId)
|
|
581
|
+
}
|
|
582
|
+
await mountButtons(nextDecks)
|
|
583
|
+
},
|
|
584
|
+
dispose,
|
|
585
|
+
}
|
|
516
586
|
}
|
package/src/deck/deck-config.ts
CHANGED
|
@@ -135,19 +135,28 @@ export const buildDeckConfigMessage = (
|
|
|
135
135
|
.map((b) => {
|
|
136
136
|
const position = b.position
|
|
137
137
|
const addon = addonByType.get(b.type)
|
|
138
|
-
const cfg =
|
|
138
|
+
const cfg = {
|
|
139
|
+
...((b.config ?? {}) as Record<string, unknown>),
|
|
140
|
+
...(b.icon !== undefined ? { icon: b.icon } : {}),
|
|
141
|
+
}
|
|
139
142
|
const label = deriveLabel(b.type, cfg)
|
|
140
143
|
const resolvedConfig = resolveConfigIcons(
|
|
141
144
|
cfg,
|
|
142
145
|
resolverOptions,
|
|
143
146
|
assetLookup,
|
|
144
147
|
)
|
|
148
|
+
if (typeof b.label === "string" && b.label.length > 0)
|
|
149
|
+
resolvedConfig.label = b.label
|
|
145
150
|
return {
|
|
146
151
|
id: b.id,
|
|
147
152
|
type: b.type,
|
|
148
153
|
...(Number.isFinite(position) ? { position } : {}),
|
|
149
154
|
config: resolvedConfig,
|
|
150
|
-
...(label
|
|
155
|
+
...(typeof b.label === "string" && b.label.length > 0
|
|
156
|
+
? { label: b.label }
|
|
157
|
+
: label !== undefined
|
|
158
|
+
? { label }
|
|
159
|
+
: {}),
|
|
151
160
|
...(addon !== undefined ? { addonName: addon.name } : {}),
|
|
152
161
|
...(addon?.frontendEntry !== undefined && addon.frontendEntry !== null
|
|
153
162
|
? { frontendEntry: addon.frontendEntry }
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type pino from "pino"
|
|
2
|
+
import type { WebSocket } from "ws"
|
|
3
|
+
|
|
4
|
+
import type { PubSub } from "@/core/pub-sub"
|
|
5
|
+
import type { WsBridge } from "@/render/ws-bridge"
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
buildDeckConfigMessage,
|
|
9
|
+
type AddonFrontendRef,
|
|
10
|
+
type AssetLookup,
|
|
11
|
+
} from "./deck-config"
|
|
12
|
+
import type { Runtime } from "./runtime"
|
|
13
|
+
import type { ResolveIconPathOptions } from "@/render/icon-source-resolver"
|
|
14
|
+
|
|
15
|
+
export interface DeckPresentationPublisher {
|
|
16
|
+
start(): void
|
|
17
|
+
refresh(options?: { force?: boolean }): void
|
|
18
|
+
sendInitial(socket: WebSocket): void
|
|
19
|
+
updateResolverOptions(options: ResolveIconPathOptions): void
|
|
20
|
+
dispose(): void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CreateDeckPresentationPublisherOptions {
|
|
24
|
+
readonly runtime: Pick<
|
|
25
|
+
Runtime,
|
|
26
|
+
| "getActiveDeck"
|
|
27
|
+
| "getAvailableOverlayDeckIcon"
|
|
28
|
+
| "getAvailableOverlayDeckName"
|
|
29
|
+
| "getOverlay"
|
|
30
|
+
| "hasOverlayDeckAvailable"
|
|
31
|
+
| "isLockActive"
|
|
32
|
+
| "navStackDepth"
|
|
33
|
+
>
|
|
34
|
+
readonly pubSub: Pick<PubSub, "subscribe">
|
|
35
|
+
readonly bridge: Pick<WsBridge, "broadcast" | "onConnection" | "sendToCaller">
|
|
36
|
+
readonly addonByType: Map<string, AddonFrontendRef>
|
|
37
|
+
readonly resolverOptions: ResolveIconPathOptions
|
|
38
|
+
readonly keyCount: number
|
|
39
|
+
readonly isCompact: boolean
|
|
40
|
+
readonly assetLookup: AssetLookup
|
|
41
|
+
readonly logger: pino.Logger
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const createDeckPresentationPublisher = (
|
|
45
|
+
options: CreateDeckPresentationPublisherOptions,
|
|
46
|
+
): DeckPresentationPublisher => {
|
|
47
|
+
const logger = options.logger.child({ component: "deck-presentation" })
|
|
48
|
+
let resolverOptions = options.resolverOptions
|
|
49
|
+
let lastPayload: string | null = null
|
|
50
|
+
let unsubscribers: Array<() => void> = []
|
|
51
|
+
|
|
52
|
+
const message = () => {
|
|
53
|
+
const activeDeck = options.runtime.getActiveDeck()
|
|
54
|
+
return buildDeckConfigMessage(
|
|
55
|
+
activeDeck,
|
|
56
|
+
options.addonByType,
|
|
57
|
+
resolverOptions,
|
|
58
|
+
{
|
|
59
|
+
navStackDepth: options.runtime.navStackDepth(),
|
|
60
|
+
hasOverlayDeckAvailable: options.runtime.hasOverlayDeckAvailable(),
|
|
61
|
+
inOverlayMode: options.runtime.getOverlay() !== null,
|
|
62
|
+
},
|
|
63
|
+
options.keyCount,
|
|
64
|
+
options.isCompact,
|
|
65
|
+
options.assetLookup,
|
|
66
|
+
options.runtime.getAvailableOverlayDeckIcon(),
|
|
67
|
+
options.runtime.getAvailableOverlayDeckName(),
|
|
68
|
+
{ lockActive: options.runtime.isLockActive() },
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const refresh = ({ force = false }: { force?: boolean } = {}): void => {
|
|
73
|
+
const next = message()
|
|
74
|
+
const payload = JSON.stringify(next)
|
|
75
|
+
if (!force && payload === lastPayload) return
|
|
76
|
+
lastPayload = payload
|
|
77
|
+
options.bridge.broadcast(next)
|
|
78
|
+
logger.debug({ deckId: next.deckId, force }, "published deck-config")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const sendInitial = (socket: WebSocket): void => {
|
|
82
|
+
const next = message()
|
|
83
|
+
if (options.bridge.sendToCaller !== undefined) {
|
|
84
|
+
options.bridge.sendToCaller(socket, next)
|
|
85
|
+
} else if (socket.readyState === socket.OPEN) {
|
|
86
|
+
socket.send(JSON.stringify(next))
|
|
87
|
+
}
|
|
88
|
+
logger.debug({ deckId: next.deckId }, "sent initial deck-config")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
start(): void {
|
|
93
|
+
if (unsubscribers.length > 0) return
|
|
94
|
+
unsubscribers = [
|
|
95
|
+
options.pubSub.subscribe("runtime:activeDeck", () => refresh()),
|
|
96
|
+
options.pubSub.subscribe("runtime:overlay-available", () => refresh()),
|
|
97
|
+
options.pubSub.subscribe("runtime:invalidate", () =>
|
|
98
|
+
refresh({ force: true }),
|
|
99
|
+
),
|
|
100
|
+
options.pubSub.subscribe("runtime:lock-mode", () =>
|
|
101
|
+
refresh({ force: true }),
|
|
102
|
+
),
|
|
103
|
+
]
|
|
104
|
+
options.bridge.onConnection(sendInitial)
|
|
105
|
+
},
|
|
106
|
+
refresh,
|
|
107
|
+
sendInitial,
|
|
108
|
+
updateResolverOptions: (next) => {
|
|
109
|
+
resolverOptions = next
|
|
110
|
+
},
|
|
111
|
+
dispose(): void {
|
|
112
|
+
for (const unsubscribe of unsubscribers) unsubscribe()
|
|
113
|
+
unsubscribers = []
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/deck/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { createStore } from "@/core/store"
|
|
|
5
5
|
import { NotImplementedError } from "@/util/errors"
|
|
6
6
|
import { createLogger } from "@/util/logger"
|
|
7
7
|
import type { KeyMacroProvider } from "@/system/providers/key-macro"
|
|
8
|
+
import type { UrlProvider } from "@/system/providers/url"
|
|
8
9
|
|
|
9
10
|
import { createActionExecutor } from "@/action/executor"
|
|
10
11
|
import { getHostContext } from "./host-context"
|
|
@@ -31,6 +32,14 @@ export {
|
|
|
31
32
|
type GestureListener,
|
|
32
33
|
type MountedButton,
|
|
33
34
|
} from "./runtime"
|
|
35
|
+
export {
|
|
36
|
+
createHostPolicyCoordinator,
|
|
37
|
+
type HostPolicyCoordinator,
|
|
38
|
+
} from "./runtime/host-policy-coordinator"
|
|
39
|
+
export {
|
|
40
|
+
createDeckPresentationPublisher,
|
|
41
|
+
type DeckPresentationPublisher,
|
|
42
|
+
} from "./deck-presentation-publisher"
|
|
34
43
|
export { getHostContext, type HostContext } from "./host-context"
|
|
35
44
|
export {
|
|
36
45
|
computeSystemButtonForSlotN1,
|
|
@@ -55,6 +64,7 @@ export interface CreateDeckRuntimeOptions {
|
|
|
55
64
|
decks: ReadonlyArray<RuntimeDeck>
|
|
56
65
|
logger?: pino.Logger
|
|
57
66
|
keyMacroProvider?: KeyMacroProvider
|
|
67
|
+
urlProvider?: UrlProvider
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
export const createDeckRuntime = (
|
|
@@ -92,6 +102,9 @@ export const createDeckRuntime = (
|
|
|
92
102
|
...(options.keyMacroProvider !== undefined
|
|
93
103
|
? { keyMacroProvider: options.keyMacroProvider }
|
|
94
104
|
: {}),
|
|
105
|
+
...(options.urlProvider !== undefined
|
|
106
|
+
? { urlProvider: options.urlProvider }
|
|
107
|
+
: {}),
|
|
95
108
|
})
|
|
96
109
|
|
|
97
110
|
methodsRef.current = methods
|