@sirenodeck/sirenodeck 0.2.10 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/config-ui/vite.config.ts +2 -0
  2. package/dist/main.mjs +1585 -807
  3. package/dist/{windows-CRWdUgCn.mjs → windows-BCvfQ3PA.mjs} +4 -4
  4. package/frontend/src/App.tsx +3 -0
  5. package/frontend/src/components/Deck.tsx +13 -2
  6. package/frontend/vite.config.ts +2 -0
  7. package/package.json +10 -1
  8. package/src/addon/api.ts +24 -1
  9. package/src/addon/data-directory.ts +52 -0
  10. package/src/api/protocol-internal.ts +5 -0
  11. package/src/builtin-addons/index.ts +0 -1
  12. package/src/builtin-addons/internal-settings/backend.ts +1 -1
  13. package/src/builtin-addons/internal-settings/buttons/brightness/common/frontend.tsx +14 -3
  14. package/src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx +6 -0
  15. package/src/builtin-addons/internal-settings/index.ts +15 -0
  16. package/src/builtin-addons/register-builtins.ts +0 -3
  17. package/src/cli/commands/addon-decks.ts +1 -0
  18. package/src/cli/commands/addon-setup-config.ts +85 -0
  19. package/src/cli/commands/addon-setup.ts +134 -0
  20. package/src/cli/commands/run.ts +57 -11
  21. package/src/cli/commands/service-manager.ts +3 -5
  22. package/src/cli/commands/start.ts +14 -81
  23. package/src/cli/commands/status-probes.ts +126 -0
  24. package/src/cli/commands/status.ts +166 -16
  25. package/src/cli/commands/stop.ts +4 -0
  26. package/src/cli/index.ts +2 -0
  27. package/src/config/environment.ts +44 -0
  28. package/src/config/loader.ts +17 -1
  29. package/src/config/schemas.ts +2 -1
  30. package/src/config/validation.ts +5 -1
  31. package/src/deck/addon-handler-bridge.ts +105 -6
  32. package/src/deck/addon-settings.ts +94 -0
  33. package/src/deck/deck-config.ts +1 -0
  34. package/src/deck/inject-config-ui-button.ts +25 -14
  35. package/src/deck/runtime/runtime.ts +175 -3
  36. package/src/deck/system-back-injection.ts +2 -0
  37. package/src/deck/system-buttons/registry.tsx +1 -0
  38. package/src/deck/system-buttons/types.ts +1 -0
  39. package/src/outputClient/real.ts +18 -1
  40. package/src/render/browser-renderer.ts +68 -12
  41. package/src/render/ws-bridge.ts +2 -0
  42. package/src/system/credentials/native.ts +74 -0
  43. package/src/system/credentials/store.ts +77 -0
  44. package/src/system/providers/notification/windows.ts +4 -4
  45. package/src/themes/default/sirenodeck.json +1 -0
  46. package/src/themes/light/sirenodeck.json +1 -0
  47. package/src/themes/manifest.ts +1 -0
  48. package/src/ui/primitives/Chip.tsx +1 -0
  49. package/src/ui/primitives/StatusIndicator.tsx +36 -0
  50. package/src/ui/primitives/index.ts +1 -0
  51. package/src/ui/surfaces/BinaryToggleSurface.tsx +52 -0
  52. package/src/ui/surfaces/LoadingSurface.tsx +34 -0
  53. package/src/ui/surfaces/index.ts +2 -0
  54. package/src/util/build-fingerprint.ts +32 -0
  55. package/src/util/daemon-control.ts +41 -0
  56. package/src/util/runtime-health.ts +57 -0
  57. package/src/util/runtime-identity.ts +25 -0
  58. package/src/vite/component-identity.ts +48 -0
  59. package/src/builtin-addons/brightness/README.md +0 -51
  60. package/src/builtin-addons/brightness/buttons/brightness/backend.ts +0 -13
  61. package/src/builtin-addons/brightness/buttons/brightness/config.ts +0 -20
  62. package/src/builtin-addons/brightness/buttons/brightness/frontend.tsx +0 -50
  63. package/src/builtin-addons/brightness/domain/macos.ts +0 -46
  64. package/src/builtin-addons/brightness/index.d.ts +0 -5
  65. package/src/builtin-addons/brightness/index.ts +0 -20
  66. package/src/builtin-addons/brightness/poller.ts +0 -27
  67. package/src/builtin-addons/brightness/sirenodeck.json +0 -6
  68. /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/darwin.ts +0 -0
  69. /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts +0 -0
  70. /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts +0 -0
  71. /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/windows.ts +0 -0
@@ -0,0 +1,94 @@
1
+ import type { AddonManifestV1 } from "@/addon/api"
2
+ import type { RuntimeButton, RuntimeDeck } from "./runtime"
3
+
4
+ const settingsId = "internal-settings:settings"
5
+
6
+ export const buildAddonSettingsDecks = (
7
+ decks: readonly RuntimeDeck[],
8
+ addons: readonly Pick<AddonManifestV1, "name" | "settings">[],
9
+ keyCount: number,
10
+ ): RuntimeDeck[] => {
11
+ const base = decks.find((deck) => deck.id === settingsId)
12
+ if (!base) return [...decks]
13
+ const compact = keyCount === 6
14
+ const entries = addons.filter((addon) => addon.settings !== undefined)
15
+ const start = compact ? 2 : 4
16
+ const available = keyCount - 1 - start
17
+ const paginated = entries.length > available
18
+ const pageSize = available - (paginated ? 1 : 0)
19
+ if (pageSize < 1) return [...decks]
20
+ const total = Math.max(1, Math.ceil(entries.length / pageSize))
21
+ const pageId = (page: number) =>
22
+ page === 0 ? settingsId : `${settingsId}-p${page + 1}`
23
+ const pages = Array.from({ length: total }, (_, page): RuntimeDeck => {
24
+ const buttons: RuntimeButton[] = compact
25
+ ? [
26
+ {
27
+ id: "app-info",
28
+ type: "internal-settings:compact-app-info",
29
+ position: 0,
30
+ config: { icon: "addon://internal-settings/logo72x72.png" },
31
+ },
32
+ {
33
+ id: "brightness",
34
+ type: "internal-settings:compact-brightness",
35
+ position: 1,
36
+ },
37
+ ]
38
+ : [
39
+ {
40
+ id: "app-info",
41
+ type: "internal-settings:app-info",
42
+ position: 0,
43
+ config: { icon: "addon://internal-settings/logo72x72.png" },
44
+ },
45
+ {
46
+ id: "brightness-down",
47
+ type: "internal-settings:brightness-down",
48
+ position: 1,
49
+ },
50
+ {
51
+ id: "brightness-up",
52
+ type: "internal-settings:brightness-up",
53
+ position: 2,
54
+ },
55
+ ]
56
+ for (const [index, addon] of entries
57
+ .slice(page * pageSize, (page + 1) * pageSize)
58
+ .entries()) {
59
+ const settings = addon.settings!
60
+ buttons.push({
61
+ id: `settings-${addon.name}`,
62
+ type: "core:change-deck",
63
+ position: start + index,
64
+ config: {
65
+ deck: settings.deck,
66
+ label: settings.label,
67
+ icon: settings.icon,
68
+ },
69
+ })
70
+ }
71
+ if (paginated)
72
+ buttons.push({
73
+ id: "page-nav",
74
+ type: "core:page-nav",
75
+ position: keyCount - 2,
76
+ config: {
77
+ currentPage: page + 1,
78
+ totalPages: total,
79
+ prevDeckId: pageId(Math.max(0, page - 1)),
80
+ nextDeckId: pageId(Math.min(total - 1, page + 1)),
81
+ },
82
+ })
83
+ return {
84
+ ...base,
85
+ id: pageId(page),
86
+ buttons,
87
+ sourceDeckId: settingsId,
88
+ projectionId: pageId(page),
89
+ pageIndex: page,
90
+ paginated,
91
+ }
92
+ })
93
+ return decks.flatMap((deck) => (deck.id === settingsId ? pages : [deck]))
94
+ }
@@ -214,6 +214,7 @@ export const buildDeckConfigMessage = (
214
214
  [deck.id]: {
215
215
  id: deck.id,
216
216
  name: deck.name ?? deck.id,
217
+ ...(deck.isModal === true ? { isModal: true } : {}),
217
218
  buttons: finalButtons,
218
219
  ...(deck.buttonColor !== undefined
219
220
  ? { buttonColor: deck.buttonColor }
@@ -3,21 +3,32 @@ import type { RuntimeDeck } from "./runtime"
3
3
  export const injectConfigUiButton = (
4
4
  decks: ReadonlyArray<RuntimeDeck>,
5
5
  configUiUrl: string,
6
+ keyCount = 15,
6
7
  ): RuntimeDeck[] =>
7
8
  decks.map((deck) =>
8
- deck.id !== "internal-settings:settings"
9
+ deck.id !== "internal-settings:settings" &&
10
+ !deck.id.startsWith("internal-settings:settings-p")
9
11
  ? deck
10
- : {
11
- ...deck,
12
- buttons: [
13
- ...deck.buttons,
14
- {
15
- id: "config-ui",
16
- type: "core:action",
17
- position: 3,
18
- config: { label: "Config UI", icon: "icon://settings" },
19
- actions: { tap: `url://${configUiUrl}` },
20
- },
21
- ],
22
- },
12
+ : keyCount === 6
13
+ ? {
14
+ ...deck,
15
+ buttons: deck.buttons.map((button) =>
16
+ button.type === "internal-settings:compact-app-info"
17
+ ? { ...button, actions: { tap: `url://${configUiUrl}` } }
18
+ : button,
19
+ ),
20
+ }
21
+ : {
22
+ ...deck,
23
+ buttons: [
24
+ ...deck.buttons,
25
+ {
26
+ id: "config-ui",
27
+ type: "core:action",
28
+ position: 3,
29
+ config: { label: "Config UI", icon: "icon://settings" },
30
+ actions: { tap: `url://${configUiUrl}` },
31
+ },
32
+ ],
33
+ },
23
34
  )
@@ -50,6 +50,7 @@ export interface RuntimeDeck {
50
50
  id: string
51
51
  name: string
52
52
  buttons: ReadonlyArray<RuntimeButton>
53
+ isModal?: boolean
53
54
  isMain?: boolean
54
55
  processNames?: ReadonlyArray<string>
55
56
  windowNames?: ReadonlyArray<string>
@@ -133,6 +134,14 @@ export interface Runtime {
133
134
  deckExists(id: string): boolean
134
135
  setDecks(decks: ReadonlyArray<RuntimeDeck>): void
135
136
  navigateToDeck(id: string, options?: { addToHistory?: boolean }): void
137
+ interruptDeck(
138
+ id: string,
139
+ options?: { onBack?: () => void | Promise<void> },
140
+ ): (() => void) | null
141
+ showModal(
142
+ id: string,
143
+ options?: { onOk?: () => void | Promise<void> },
144
+ ): (() => void) | null
136
145
  goBack(): void
137
146
  setOverlay(
138
147
  deckId: string | null,
@@ -212,6 +221,17 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
212
221
  }
213
222
  let brightness = 50
214
223
  let lockActive = false
224
+ const modals: Array<{ deckId: string; onOk?: () => void | Promise<void> }> =
225
+ []
226
+ let deferredOverlay: {
227
+ deckId: string | null
228
+ source?: "autoShow" | "manual"
229
+ } | null = null
230
+ let interruption: {
231
+ deckId: string
232
+ onBack?: () => void | Promise<void>
233
+ backPending?: boolean
234
+ } | null = null
215
235
  let legacyActiveApp: Pick<ActiveAppProvider, "getActive" | "stop"> = {
216
236
  getActive: async () => null,
217
237
  stop: async () => undefined,
@@ -225,6 +245,19 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
225
245
 
226
246
  const setDecks = (next: ReadonlyArray<RuntimeDeck>): void => {
227
247
  decks = next
248
+ const activeModal = modals[0]
249
+ for (let i = modals.length - 1; i >= 0; i--) {
250
+ if (deckById(modals[i]!.deckId) === undefined) modals.splice(i, 1)
251
+ }
252
+ if (!lockActive && activeModal && modals[0] !== activeModal) {
253
+ pubSub.publish("runtime:deck-inactive", { deckId: activeModal.deckId })
254
+ pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() })
255
+ }
256
+ if (interruption !== null && deckById(interruption.deckId) === undefined) {
257
+ const previous = interruption.deckId
258
+ interruption = null
259
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
260
+ }
228
261
  // ponytail: rebuild a global button-id → ref map so bare-id lookups in
229
262
  // findButton are O(1) instead of scanning all decks in deck order. Set
230
263
  // first-wins (not last-wins) to preserve the legacy scan behavior.
@@ -276,11 +309,15 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
276
309
  const id = getActiveDeckId()
277
310
  const deck = deckById(id)
278
311
  if (deck === undefined) throw new Error(`Active deck '${id}' not found`)
279
- return deck
312
+ return !lockActive && modals[0]?.deckId === id
313
+ ? { ...deck, isModal: true }
314
+ : deck
280
315
  }
281
316
 
282
317
  const getActiveDeckId = (): string => {
283
318
  if (lockActive) return "core:lock"
319
+ if (modals[0]) return modals[0].deckId
320
+ if (interruption !== null) return interruption.deckId
284
321
  // ponytail: while overlay mode is on, transientDeckId (used by page-nav)
285
322
  // must take precedence — otherwise paginated overlay pages are invisible
286
323
  // to the runtime, and dismissing overlay after paginating restores the
@@ -302,6 +339,53 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
302
339
  navStack[navStack.length - 1] ??
303
340
  mainDeck.id
304
341
 
342
+ const showModal = (
343
+ id: string,
344
+ options?: { onOk?: () => void | Promise<void> },
345
+ ): (() => void) | null => {
346
+ if (!deckById(id)) return null
347
+ const previous = getActiveDeckId()
348
+ const entry = { deckId: id, onOk: options?.onOk }
349
+ modals.push(entry)
350
+ if (!lockActive && modals[0] === entry) {
351
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
352
+ pubSub.publish("runtime:activeDeck", { deckId: id })
353
+ }
354
+ return () => {
355
+ const index = modals.indexOf(entry)
356
+ if (index < 0) return
357
+ const wasActive = index === 0 && !lockActive
358
+ modals.splice(index, 1)
359
+ if (wasActive) {
360
+ pubSub.publish("runtime:deck-inactive", { deckId: id })
361
+ pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() })
362
+ if (modals.length === 0 && deferredOverlay) {
363
+ const pending = deferredOverlay
364
+ deferredOverlay = null
365
+ setOverlay(pending.deckId, { source: pending.source })
366
+ }
367
+ }
368
+ }
369
+ }
370
+
371
+ const interruptDeck = (
372
+ id: string,
373
+ options?: { onBack?: () => void | Promise<void> },
374
+ ): (() => void) | null => {
375
+ if (lockActive || deckById(id) === undefined) return null
376
+ const previous = getActiveDeckId()
377
+ const current = { deckId: id, onBack: options?.onBack }
378
+ interruption = current
379
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
380
+ pubSub.publish("runtime:activeDeck", { deckId: id })
381
+ return () => {
382
+ if (interruption !== current) return
383
+ interruption = null
384
+ pubSub.publish("runtime:deck-inactive", { deckId: id })
385
+ pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() })
386
+ }
387
+ }
388
+
305
389
  const enterLock = (): {
306
390
  activeDeckId: string
307
391
  overlayDeckId: string | null
@@ -312,6 +396,11 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
312
396
  }
313
397
  if (lockActive) return snapshot
314
398
  lockActive = true
399
+ if (interruption !== null) {
400
+ const previous = interruption.deckId
401
+ interruption = null
402
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
403
+ }
315
404
  logger.info(snapshot, "runtime: lock active")
316
405
  pubSub.publish("runtime:lock-mode", {
317
406
  active: true,
@@ -326,6 +415,7 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
326
415
  id: string,
327
416
  navOptions?: { addToHistory?: boolean },
328
417
  ): void => {
418
+ if (!lockActive && modals.length > 0) return
329
419
  if (id === getActiveDeckId()) return
330
420
  let resolvedId = id
331
421
  let target = deckById(id)
@@ -344,6 +434,15 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
344
434
  logger.warn({ deckId: id }, "navigateToDeck: deck not found")
345
435
  return
346
436
  }
437
+ if (interruption !== null) {
438
+ const previous = interruption.deckId
439
+ interruption = null
440
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
441
+ if (getActiveDeckId() === resolvedId) {
442
+ pubSub.publish("runtime:activeDeck", { deckId: resolvedId })
443
+ return
444
+ }
445
+ }
347
446
  const previousActiveId = getActiveDeckId()
348
447
  if (overlayDeckId !== null) {
349
448
  // ponytail: while overlay mode is on, both change-deck (addToHistory:true)
@@ -371,12 +470,20 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
371
470
  }
372
471
 
373
472
  const goBack = (): void => {
473
+ if (!lockActive && modals.length > 0) return
474
+ if (interruption !== null) {
475
+ const previous = interruption.deckId
476
+ interruption = null
477
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
478
+ pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() })
479
+ return
480
+ }
374
481
  if (overlayDeckId !== null) {
375
482
  const stack = overlayNavStacks.get(overlayDeckId)
376
483
  if (stack !== undefined && stack.length > 1) {
377
- stack.pop()
484
+ const departed = stack.pop()!
378
485
  const prev = stack[stack.length - 1]!
379
- pubSub.publish("runtime:deck-inactive", { deckId: prev })
486
+ pubSub.publish("runtime:deck-inactive", { deckId: departed })
380
487
  pubSub.publish("runtime:activeDeck", { deckId: prev })
381
488
  } else {
382
489
  setOverlay(null)
@@ -416,10 +523,23 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
416
523
  deckId: string | null,
417
524
  opts?: { source?: "autoShow" | "manual" },
418
525
  ): void => {
526
+ if (!lockActive && modals.length > 0) {
527
+ deferredOverlay = {
528
+ deckId,
529
+ ...(opts?.source ? { source: opts.source } : {}),
530
+ }
531
+ return
532
+ }
419
533
  if (deckId !== null && deckById(deckId) === undefined) {
420
534
  logger.warn({ deckId }, "setOverlay: deck not found")
421
535
  return
422
536
  }
537
+ if (interruption !== null && deckId === overlayDeckId) return
538
+ if (interruption !== null && deckId !== overlayDeckId) {
539
+ const previous = interruption.deckId
540
+ interruption = null
541
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
542
+ }
423
543
  if (deckId !== null && !overlayNavStacks.has(deckId)) {
424
544
  overlayNavStacks.set(deckId, [deckId])
425
545
  }
@@ -496,13 +616,53 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
496
616
  }
497
617
 
498
618
  const handleSystemButton = (type: string, gesture: GestureKind): boolean => {
619
+ if (
620
+ (type === "core:back" || type === "core:modal-ok") &&
621
+ !lockActive &&
622
+ modals[0]
623
+ ) {
624
+ if (gesture === "tap" || gesture === "hold") {
625
+ const entry = modals.shift()!
626
+ pubSub.publish("runtime:deck-inactive", { deckId: entry.deckId })
627
+ pubSub.publish("runtime:activeDeck", { deckId: getActiveDeckId() })
628
+ if (modals.length === 0 && deferredOverlay) {
629
+ const pending = deferredOverlay
630
+ deferredOverlay = null
631
+ setOverlay(pending.deckId, { source: pending.source })
632
+ }
633
+ if (entry.onOk)
634
+ void Promise.resolve()
635
+ .then(entry.onOk)
636
+ .catch((err) => logger.error({ err }, "modal OK action failed"))
637
+ }
638
+ return true
639
+ }
499
640
  if (type === "core:back") {
500
641
  if (gesture === "tap") {
642
+ if (interruption?.onBack) {
643
+ const current = interruption
644
+ if (current.backPending) return true
645
+ current.backPending = true
646
+ void Promise.resolve()
647
+ .then(current.onBack)
648
+ .catch((err) =>
649
+ logger.error({ err }, "interruption back action failed"),
650
+ )
651
+ .finally(() => {
652
+ current.backPending = false
653
+ })
654
+ return true
655
+ }
501
656
  goBack()
502
657
  return true
503
658
  }
504
659
  if (gesture === "hold") {
505
660
  // ponytail: hold always goes to main, never toggles overlay
661
+ if (interruption !== null) {
662
+ const previous = interruption.deckId
663
+ interruption = null
664
+ pubSub.publish("runtime:deck-inactive", { deckId: previous })
665
+ }
506
666
  if (overlayDeckId !== null) setOverlay(null)
507
667
  navStack.length = 0
508
668
  navStack.push(mainDeck.id)
@@ -582,6 +742,8 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
582
742
  return
583
743
  }
584
744
 
745
+ if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return
746
+
585
747
  try {
586
748
  if (handleSystemButton(found.button.type, gesture)) {
587
749
  return
@@ -772,6 +934,7 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
772
934
  logger.warn({ buttonId }, "dispatchGesture: button not found")
773
935
  return
774
936
  }
937
+ if (!lockActive && modals[0] && found.deckId !== modals[0].deckId) return
775
938
  gestureListener?.(found.button.id, {
776
939
  gesture,
777
940
  at: Date.now(),
@@ -817,6 +980,13 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
817
980
  reason: "session-unlocked",
818
981
  })
819
982
  pubSub.publish("runtime:invalidate", undefined)
983
+ if (modals[0])
984
+ pubSub.publish("runtime:activeDeck", { deckId: modals[0].deckId })
985
+ else if (deferredOverlay) {
986
+ const pending = deferredOverlay
987
+ deferredOverlay = null
988
+ setOverlay(pending.deckId, { source: pending.source })
989
+ }
820
990
  }
821
991
 
822
992
  const startLegacyPolicy = (): void => {
@@ -876,6 +1046,8 @@ export const createRuntime = (options: CreateRuntimeOptions): Runtime => {
876
1046
  deckById(id) !== undefined || deckById(`${id}-p1`) !== undefined,
877
1047
  setDecks,
878
1048
  navigateToDeck,
1049
+ interruptDeck,
1050
+ showModal,
879
1051
  goBack,
880
1052
  setOverlay,
881
1053
  getOverlay,
@@ -10,6 +10,7 @@ export interface RuntimeDeck {
10
10
  config?: unknown
11
11
  }>
12
12
  isMain?: boolean
13
+ isModal?: boolean
13
14
  processNames?: ReadonlyArray<string>
14
15
  windowNames?: ReadonlyArray<string>
15
16
  autoShow?: boolean
@@ -28,6 +29,7 @@ export const computeSystemButtonForSlotN1 = (
28
29
  state: RuntimeState,
29
30
  ): SystemButtonType | null => {
30
31
  if (state.lockActive === true) return null
32
+ if (deck.isModal) return "core:modal-ok"
31
33
  if (deck.isMain) return "core:settings-entry"
32
34
  // `core:back` gives the split surface distinct tap (back) and dbl-tap
33
35
  // (overlay toggle) actions, including while an overlay is active.
@@ -16,6 +16,7 @@ const SYSTEM_BUTTON_LAYOUT: Record<
16
16
  { source: string; label: string; details?: string }
17
17
  > = {
18
18
  "core:back": { source: "icon://arrow-left", label: "Back" },
19
+ "core:modal-ok": { source: "icon://check", label: "OK" },
19
20
  "core:settings-entry": { source: "icon://settings", label: "Settings" },
20
21
  "core:overlay-toggle": { source: "icon://layers", label: "Overlay" },
21
22
  "core:temporary-error": {
@@ -3,6 +3,7 @@
3
3
  // system button. Keeping the system-button surface small and deliberate.
4
4
  export const SYSTEM_BUTTON_TYPES = [
5
5
  "core:back",
6
+ "core:modal-ok",
6
7
  "core:settings-entry",
7
8
  "core:overlay-toggle",
8
9
  "core:temporary-error",
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs"
2
2
  import { fileURLToPath } from "node:url"
3
3
 
4
4
  import type pino from "pino"
5
+ import sharp from "sharp"
5
6
 
6
7
  import { createGestureDetector } from "@/core/gesture-state"
7
8
  import { pushBlackFrame } from "@/device/black-frame"
@@ -294,10 +295,26 @@ export class RealOutputClient implements OutputClient {
294
295
 
295
296
  logger.info({ frontendUrl }, "real mode: frontend URL")
296
297
 
298
+ let rendererFailed = false
297
299
  renderer = new BrowserRenderer({
298
300
  frontendUrl: `${frontendUrl}${frontendUrl.includes("?") ? "&" : "?"}compact=1`,
299
301
  device,
300
302
  logger,
303
+ onFatalCrash: async () => {
304
+ rendererFailed = true
305
+ try {
306
+ const svg = Buffer.from(
307
+ '<svg xmlns="http://www.w3.org/2000/svg" width="72" height="72"><rect width="72" height="72" fill="#7f1d1d"/><text x="36" y="28" fill="white" text-anchor="middle" font-family="sans-serif" font-weight="bold" font-size="12">RENDER</text><text x="36" y="47" fill="white" text-anchor="middle" font-family="sans-serif" font-weight="bold" font-size="12">ERROR</text></svg>',
308
+ )
309
+ const pixels = await sharp(svg).removeAlpha().raw().toBuffer()
310
+ for (let i = 0; i < device.getKeyCount(); i++)
311
+ await device.fillKeyBuffer(i, pixels)
312
+ } catch (err) {
313
+ logger.error({ err }, "failed to display renderer error")
314
+ } finally {
315
+ opts.onChildCrash?.()
316
+ }
317
+ },
301
318
  ...(opts.intervalMs !== undefined
302
319
  ? { intervalMs: opts.intervalMs }
303
320
  : {}),
@@ -330,7 +347,7 @@ export class RealOutputClient implements OutputClient {
330
347
  wsUrl: opts.bridge.url,
331
348
  childPids,
332
349
  async pushBlackFrame(): Promise<void> {
333
- await pushBlackFrame(device, logger)
350
+ if (!rendererFailed) await pushBlackFrame(device, logger)
334
351
  },
335
352
  async pushRawImage(filePath: string): Promise<void> {
336
353
  try {
@@ -7,6 +7,7 @@ import type pino from "pino"
7
7
 
8
8
  import { BufferChangeTracker } from "./buffer-hash"
9
9
  import { CadenceTimer, EventDebouncer } from "./screenshot-cadence"
10
+ import { runtimeHealth } from "@/util/runtime-health"
10
11
 
11
12
  export interface PlaywrightLike {
12
13
  chromium: {
@@ -48,6 +49,7 @@ export interface BrowserRendererOptions {
48
49
  readonly intervalMs?: number
49
50
  readonly eventDebounceMs?: number
50
51
  readonly playwrightFactory?: () => PlaywrightLike | Promise<PlaywrightLike>
52
+ readonly onFatalCrash?: () => Promise<void>
51
53
  }
52
54
 
53
55
  const DEFAULT_INTERVAL_MS = 500
@@ -77,6 +79,7 @@ export class BrowserRenderer {
77
79
  private context: ContextLike | null = null
78
80
  private page: PageLike | null = null
79
81
  private running = false
82
+ private recovering: Promise<void> | null = null
80
83
  private readonly logger: pino.Logger
81
84
 
82
85
  constructor(private readonly options: BrowserRendererOptions) {
@@ -126,14 +129,7 @@ export class BrowserRenderer {
126
129
  }
127
130
  throw err
128
131
  }
129
- const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount())
130
- const vpWidth = columns * BUTTON_SIZE_PX
131
- const vpHeight = rows * BUTTON_SIZE_PX
132
- this.context = await this.browser.newContext({
133
- viewport: { width: vpWidth, height: vpHeight },
134
- })
135
- this.page = await this.context.newPage()
136
- await this.page.goto(this.options.frontendUrl, { waitUntil: "networkidle" })
132
+ await this.openPage()
137
133
  if (this.pubSub) {
138
134
  this.subscriptions.push(
139
135
  {
@@ -152,6 +148,17 @@ export class BrowserRenderer {
152
148
  this.running = true
153
149
  }
154
150
 
151
+ private async openPage(): Promise<void> {
152
+ const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount())
153
+ const vpWidth = columns * BUTTON_SIZE_PX
154
+ const vpHeight = rows * BUTTON_SIZE_PX
155
+ this.context = await this.browser!.newContext({
156
+ viewport: { width: vpWidth, height: vpHeight },
157
+ })
158
+ this.page = await this.context.newPage()
159
+ await this.page.goto(this.options.frontendUrl, { waitUntil: "networkidle" })
160
+ }
161
+
155
162
  /**
156
163
  * Repaints every key on the next tick.
157
164
  *
@@ -172,9 +179,12 @@ export class BrowserRenderer {
172
179
  this.debouncer.dispose()
173
180
  for (const sub of this.subscriptions) sub.unsubscribe()
174
181
  this.subscriptions.length = 0
175
- if (this.page) await this.page.close()
176
- if (this.context) await this.context.close()
177
- if (this.browser) await this.browser.close()
182
+ await this.recovering
183
+ await Promise.allSettled([
184
+ this.page?.close(),
185
+ this.context?.close(),
186
+ this.browser?.close(),
187
+ ])
178
188
  this.page = null
179
189
  this.context = null
180
190
  this.browser = null
@@ -182,8 +192,43 @@ export class BrowserRenderer {
182
192
 
183
193
  private static readonly BLANK_THRESHOLD = 20
184
194
 
195
+ private async recover(): Promise<void> {
196
+ runtimeHealth.setRenderer("recovering")
197
+ const factory =
198
+ this.options.playwrightFactory ??
199
+ (async (): Promise<PlaywrightLike> =>
200
+ (await import("playwright")) as PlaywrightLike)
201
+ for (let attempt = 1; attempt <= 3 && this.running; attempt++) {
202
+ await Promise.allSettled([
203
+ this.page?.close(),
204
+ this.context?.close(),
205
+ this.browser?.close(),
206
+ ])
207
+ this.page = null
208
+ this.context = null
209
+ this.browser = null
210
+ if (!this.running) break
211
+ try {
212
+ const playwright = await factory()
213
+ this.browser = await playwright.chromium.launch({ headless: true })
214
+ await this.openPage()
215
+ await this.page!.screenshot({ type: "png" })
216
+ this.tracker.reset()
217
+ this.logger.info({ attempt }, "browser renderer recovered")
218
+ return
219
+ } catch (err) {
220
+ this.logger.warn({ err, attempt }, "browser renderer recovery failed")
221
+ }
222
+ }
223
+ if (this.running) {
224
+ this.cadence.stop()
225
+ runtimeHealth.setRenderer("failed")
226
+ await this.options.onFatalCrash?.()
227
+ }
228
+ }
229
+
185
230
  private async tick(source: "timer" | "event"): Promise<void> {
186
- if (!this.page) return
231
+ if (!this.page || this.recovering) return
187
232
  try {
188
233
  const png = await this.page.screenshot({ type: "png" })
189
234
  const { columns, rows } = gridForKeyCount(
@@ -231,8 +276,19 @@ export class BrowserRenderer {
231
276
  )
232
277
  }
233
278
  }
279
+ runtimeHealth.setRenderer("healthy", Date.now())
234
280
  } catch (err) {
235
281
  this.logger.warn({ err, source }, "renderer tick failed")
282
+ if (
283
+ /target crashed|target page, context or browser has been closed/i.test(
284
+ (err as Error).message,
285
+ )
286
+ ) {
287
+ this.recovering ??= this.recover().finally(() => {
288
+ this.recovering = null
289
+ })
290
+ await this.recovering
291
+ }
236
292
  }
237
293
  }
238
294
  }
@@ -1,6 +1,7 @@
1
1
  import type { Server as HttpServer } from "node:http"
2
2
  import { WebSocketServer, type WebSocket } from "ws"
3
3
  import type pino from "pino"
4
+ import { runtimeIdentity } from "@/util/runtime-identity"
4
5
 
5
6
  import type { DeviceDescriptor } from "@/device/registry"
6
7
  import { createLogger } from "@/util/logger"
@@ -161,6 +162,7 @@ export const startWsBridge = (options: WsBridgeOptions): Promise<WsBridge> => {
161
162
  const ack = helloAckMessageSchema.parse({
162
163
  type: "hello-ack",
163
164
  version: PROTOCOL_VERSION,
165
+ build: runtimeIdentity,
164
166
  ...(currentDevice !== null ? { device: currentDevice } : {}),
165
167
  config:
166
168
  currentTheme !== undefined ? { theme: currentTheme.name } : {},