@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.
Files changed (84) hide show
  1. package/LICENSE +674 -21
  2. package/bin/dev.js +12 -2
  3. package/dist/main.mjs +3655 -1657
  4. package/package.json +18 -16
  5. package/src/api/protocol-internal.ts +16 -1
  6. package/src/assets/logo.png +0 -0
  7. package/src/assets/logo72x72.png +0 -0
  8. package/src/builtin-addons/brightness/buttons/brightness/config.ts +12 -2
  9. package/src/builtin-addons/coding-agents/buttons/agent/config.ts +5 -1
  10. package/src/builtin-addons/coding-agents/buttons/summary/config.ts +15 -3
  11. package/src/builtin-addons/coding-agents/buttons/summary/frontend.tsx +3 -3
  12. package/src/builtin-addons/coding-agents/global/backend.ts +56 -34
  13. package/src/builtin-addons/coding-agents/providers/opencode.ts +4 -5
  14. package/src/builtin-addons/core/buttons/action/config.ts +5 -2
  15. package/src/builtin-addons/core/buttons/change-deck/config.ts +6 -3
  16. package/src/builtin-addons/core/buttons/media-sample/config.ts +2 -2
  17. package/src/builtin-addons/core/buttons/toggle/config.ts +26 -9
  18. package/src/builtin-addons/date-time/buttons/custom/config.ts +5 -1
  19. package/src/builtin-addons/date-time/buttons/date/config.ts +2 -2
  20. package/src/builtin-addons/date-time/buttons/time/config.ts +5 -1
  21. package/src/builtin-addons/emoji-selector/buttons/category/config.ts +3 -3
  22. package/src/builtin-addons/emoji-selector/buttons/emoji/config.ts +5 -2
  23. package/src/builtin-addons/emoji-selector/support.ts +5 -2
  24. package/src/builtin-addons/global-services.ts +23 -0
  25. package/src/builtin-addons/internal-settings/buttons/app-info/config.ts +2 -1
  26. package/src/builtin-addons/internal-settings/buttons/brightness-down/config.ts +6 -1
  27. package/src/builtin-addons/internal-settings/buttons/brightness-up/config.ts +6 -1
  28. package/src/builtin-addons/media/backend.ts +54 -0
  29. package/src/builtin-addons/media/buttons/volume/volume-down/config.ts +1 -1
  30. package/src/builtin-addons/media/buttons/volume/volume-up/config.ts +1 -1
  31. package/src/builtin-addons/session/buttons/time/config.ts +1 -1
  32. package/src/builtin-addons/system-status/buttons/system-status/schemas.ts +32 -6
  33. package/src/builtin-addons/system-status/manifest.ts +49 -0
  34. package/src/builtin-addons/value-display/buttons/value-display/config.ts +23 -9
  35. package/src/builtin-addons/weather/buttons/weather/config.ts +11 -6
  36. package/src/cli/coding-agents-onboarding.ts +181 -34
  37. package/src/cli/commands/command-executor.ts +61 -0
  38. package/src/cli/commands/emulator-mode.ts +17 -2
  39. package/src/cli/commands/network-bind.ts +13 -9
  40. package/src/cli/commands/restart.ts +15 -5
  41. package/src/cli/commands/run.ts +174 -317
  42. package/src/cli/commands/service/render-template.ts +10 -0
  43. package/src/cli/commands/skills.ts +106 -0
  44. package/src/cli/commands/start.ts +39 -9
  45. package/src/cli/commands/stop.ts +3 -2
  46. package/src/cli/commands/system-requirements.ts +1 -0
  47. package/src/cli/index.ts +16 -3
  48. package/src/cli/main.ts +15 -2
  49. package/src/cli/package-manager.ts +6 -0
  50. package/src/cli/skills-first-run.ts +46 -0
  51. package/src/cli/startup-display.ts +35 -17
  52. package/src/config/mutation.ts +13 -1
  53. package/src/config/schemas.ts +3 -3
  54. package/src/config/validation.ts +7 -1
  55. package/src/core/icon-asset-registry.ts +11 -6
  56. package/src/deck/addon-handler-bridge.ts +246 -176
  57. package/src/deck/deck-config.ts +11 -2
  58. package/src/deck/deck-presentation-publisher.ts +116 -0
  59. package/src/deck/index.ts +13 -0
  60. package/src/deck/inject-config-ui-button.ts +23 -0
  61. package/src/deck/methods.ts +23 -0
  62. package/src/deck/position-settings-version-button.ts +20 -0
  63. package/src/deck/runtime/host-policy-coordinator.ts +186 -0
  64. package/src/deck/runtime/runtime.ts +123 -250
  65. package/src/deck/system-back-injection.ts +2 -1
  66. package/src/device/reconnecting.ts +8 -1
  67. package/src/index.ts +1 -2
  68. package/src/outputClient/emulator.ts +13 -0
  69. package/src/outputClient/index.ts +8 -0
  70. package/src/outputClient/real.ts +40 -45
  71. package/src/outputClient/remote-mirror.ts +77 -0
  72. package/src/outputClient/types.ts +2 -0
  73. package/src/render/editor-handler.ts +12 -1
  74. package/src/render/frontend-bridge-url.ts +10 -0
  75. package/src/render/push-startup-screen.ts +76 -0
  76. package/src/render/ws-bridge.ts +2 -0
  77. package/src/system/providers/active-app/capture-file.ts +61 -0
  78. package/src/system/providers/active-app/wayland-gnome.ts +26 -10
  79. package/src/system/providers/active-app.ts +6 -0
  80. package/src/system/providers/clipboard/darwin.ts +28 -4
  81. package/src/system/providers/url.ts +57 -0
  82. package/src/util/logger.ts +19 -3
  83. package/src/version.ts +3 -1
  84. 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
- staticAddonModule(addon.name) ??
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
- for (const deck of decks) {
259
- for (const button of deck.buttons) {
260
- const buttonType = button.type
261
-
262
- let addonName: string | null = null
263
- let resolvedButtonType: string | null = null
264
- for (const addon of allAddons) {
265
- if (addon.types.includes(buttonType)) {
266
- addonName = addon.name
267
- resolvedButtonType = buttonType
268
- break
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
- if (
271
- typeof addon.defaultButton === "string" &&
272
- addon.name === buttonType
273
- ) {
274
- addonName = addon.name
275
- resolvedButtonType = addon.defaultButton
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
- if (addonName === null || resolvedButtonType === null) continue
345
+ const exported = addonMod
346
+ ? (addonMod.manifest ??
347
+ (addonMod.default && typeof addonMod.default === "object"
348
+ ? addonMod.default
349
+ : null))
350
+ : null
281
351
 
282
- const globalMethods = addonMethods.get(addonName) ?? {}
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
- let addonMod: AddonModule | null = null
289
- for (const addon of allAddons) {
290
- if (addon.name !== addonName) continue
291
- if (addon.frontendEntry === null) continue
292
- try {
293
- addonMod =
294
- staticAddonModule(addon.name) ??
295
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
- const exported = addonMod
309
- ? (addonMod.manifest ??
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
- const buttonTypeEntry = manifest.buttonTypes?.[resolvedButtonType]
328
- if (buttonTypeEntry?.service === undefined) continue
329
-
330
- const buttonService = buttonTypeEntry.service
331
- const buttonCtx: AddonButtonServiceContext<unknown> = {
332
- config: button.config ?? {},
333
- buttonId: button.id,
334
- ...(button.position !== undefined ? { position: button.position } : {}),
335
- addonName,
336
- methods: Object.freeze(buttonMethods),
337
- coreMethods: methods,
338
- publish: (channel: string, data: unknown) =>
339
- pubSub.publish(channel, data),
340
- executor,
341
- signal: abortController.signal,
342
- store,
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
- const buttonAbort = new AbortController()
346
- abortController.signal.addEventListener("abort", () =>
347
- buttonAbort.abort(),
348
- )
384
+ const buttonAbort = new AbortController()
385
+ abortController.signal.addEventListener("abort", () =>
386
+ buttonAbort.abort(),
387
+ )
349
388
 
350
- const wrappedCtx = {
351
- ...buttonCtx,
352
- signal: buttonAbort.signal,
353
- }
389
+ const wrappedCtx = {
390
+ ...buttonCtx,
391
+ signal: buttonAbort.signal,
392
+ }
354
393
 
355
- const existing = deckButtonCleanup.get(deck.id) ?? []
356
- existing.push({ buttonAbort, buttonService, wrappedCtx })
357
- deckButtonCleanup.set(deck.id, existing)
394
+ const existing = deckButtonCleanup.get(deck.id) ?? []
395
+ existing.push({ handlerId, buttonAbort, buttonService, wrappedCtx })
396
+ deckButtonCleanup.set(deck.id, existing)
358
397
 
359
- try {
360
- buttonService.onMount?.(wrappedCtx)
361
- } catch (err) {
362
- logger.error({ addonName, buttonType, err }, `addon onMount threw`)
363
- }
398
+ try {
399
+ buttonService.onMount?.(wrappedCtx)
400
+ } catch (err) {
401
+ logger.error({ addonName, buttonType, err }, `addon onMount threw`)
402
+ }
364
403
 
365
- const allowedGestures = buttonService.gestureHandlers
366
- const handler = {
367
- async onTap(ctx: {
368
- buttonId: string
369
- config: unknown
370
- gesture: string
371
- }) {
372
- if (allowedGestures === undefined || !allowedGestures.includes("tap"))
373
- return
374
- try {
375
- await buttonService.onTap?.(wrappedCtx)
376
- } catch (err) {
377
- logger.error(
378
- { addonName, buttonType: resolvedButtonType, err },
379
- `addon onTap failed`,
380
- )
381
- }
382
- },
383
- async onDblTap(ctx: {
384
- buttonId: string
385
- config: unknown
386
- gesture: string
387
- }) {
388
- if (
389
- allowedGestures === undefined ||
390
- !allowedGestures.includes("dbl-tap")
391
- )
392
- return
393
- try {
394
- await buttonService.onDblTap?.(wrappedCtx)
395
- } catch (err) {
396
- logger.error(
397
- { addonName, buttonType: resolvedButtonType, err },
398
- `addon onDblTap failed`,
399
- )
400
- }
401
- },
402
- async onHold(ctx: {
403
- buttonId: string
404
- config: unknown
405
- gesture: string
406
- }) {
407
- if (
408
- allowedGestures === undefined ||
409
- !allowedGestures.includes("hold")
410
- )
411
- return
412
- try {
413
- await buttonService.onHold?.(wrappedCtx)
414
- } catch (err) {
415
- logger.error(
416
- { addonName, buttonType: resolvedButtonType, err },
417
- `addon onHold failed`,
418
- )
419
- }
420
- },
421
- dispose() {
422
- buttonAbort.abort()
423
- try {
424
- buttonService.dispose?.(wrappedCtx)
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
- runtime.registerButtonHandler(`${deck.id}:${button.id}`, handler)
432
- registeredHandlerIds.add(`${deck.id}:${button.id}`)
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
- for (const handlerId of registeredHandlerIds) {
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 { dispose }
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
  }
@@ -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 = (b.config ?? {}) as Record<string, unknown>
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 !== undefined ? { 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