@sirenodeck/sirenodeck 0.2.7 → 0.2.9
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/config-ui/index.html +13 -0
- package/config-ui/src/App.tsx +675 -0
- package/config-ui/src/DeckFrame.tsx +445 -0
- package/config-ui/src/Shell.tsx +108 -0
- package/config-ui/src/SidePanel.tsx +96 -0
- package/config-ui/src/bridge-log-store.ts +115 -0
- package/config-ui/src/bridge.ts +303 -0
- package/config-ui/src/components/ActionValueEditor.tsx +209 -0
- package/config-ui/src/components/ButtonActionsEditor.tsx +84 -0
- package/config-ui/src/components/DisconnectedOverlay.tsx +77 -0
- package/config-ui/src/components/EmojiPicker.tsx +65 -0
- package/config-ui/src/components/IconPicker.tsx +264 -0
- package/config-ui/src/components/MacroPreview.tsx +22 -0
- package/config-ui/src/components/ReconnectingBanner.tsx +35 -0
- package/config-ui/src/gesture.ts +45 -0
- package/config-ui/src/index.css +8 -0
- package/config-ui/src/main.tsx +20 -0
- package/config-ui/src/pages/AboutPage.tsx +65 -0
- package/config-ui/src/pages/AddonsPage.tsx +232 -0
- package/config-ui/src/pages/BridgeLogsPage.tsx +94 -0
- package/config-ui/src/pages/ButtonConfigEditor/ButtonAppearanceFields.tsx +77 -0
- package/config-ui/src/pages/ButtonConfigEditor/ButtonTypePicker.tsx +80 -0
- package/config-ui/src/pages/ButtonConfigEditor/ConfigForm.tsx +50 -0
- package/config-ui/src/pages/ButtonConfigEditor/FormFieldParts.tsx +23 -0
- package/config-ui/src/pages/ButtonConfigEditor/PositionPicker.tsx +68 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ActionControl.tsx +27 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ArrayControl.tsx +77 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/BooleanControl.tsx +34 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/DeckSelectControl.tsx +47 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/EmojiControl.tsx +70 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/IconControl.tsx +31 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ObjectControl.tsx +52 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/RecordControl.tsx +104 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/SelectControl.tsx +46 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ShellControl.tsx +29 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/TextControl.tsx +36 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/UnionControl.tsx +96 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/registry.ts +17 -0
- package/config-ui/src/pages/ButtonConfigEditor/types.ts +67 -0
- package/config-ui/src/pages/ButtonConfigEditor/utils.ts +56 -0
- package/config-ui/src/pages/ButtonConfigEditor.tsx +226 -0
- package/config-ui/src/pages/ConfigPage.tsx +326 -0
- package/config-ui/src/pages/DecksPage.tsx +104 -0
- package/config-ui/src/pages/EditorPage.tsx +1697 -0
- package/config-ui/src/pages/ServiceLogsPage.tsx +130 -0
- package/config-ui/vite.config.ts +105 -0
- package/dist/main.mjs +299 -41557
- package/frontend/index.html +12 -0
- package/frontend/src/App.tsx +536 -0
- package/frontend/src/__mocks__/addons-registry.ts +2 -0
- package/frontend/src/__mocks__/theme.ts +1 -0
- package/frontend/src/__mocks__/themes-manifest.tsx +78 -0
- package/frontend/src/__mocks__/token.ts +2 -0
- package/frontend/src/bridge/client.ts +186 -0
- package/frontend/src/bridge/use-button-action.ts +31 -0
- package/frontend/src/bridge/ws-context.tsx +24 -0
- package/frontend/src/components/Deck.tsx +486 -0
- package/frontend/src/components/DisconnectedOverlay.tsx +82 -0
- package/frontend/src/components/ErrorBoundary.tsx +92 -0
- package/frontend/src/components/ReconnectingBanner.tsx +40 -0
- package/frontend/src/index.css +40 -0
- package/frontend/src/main.tsx +23 -0
- package/frontend/vite.config.ts +132 -0
- package/package.json +20 -6
- package/src/builtin-addons/internal-settings/index.ts +0 -1
- package/src/builtin-addons/internal-settings/logo72x72.png +0 -0
- package/src/cli/commands/emulator-mode.ts +26 -4
- package/src/cli/commands/service-manager.ts +53 -1
- package/src/device/black-frame.ts +3 -7
- package/src/vite/virtual-modules.ts +16 -1
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUTTON_SIZE_PX,
|
|
3
|
+
DECK_GAP_PX,
|
|
4
|
+
DECK_PADDING_PX,
|
|
5
|
+
gridForKeyCount,
|
|
6
|
+
type DeviceModelSpec,
|
|
7
|
+
} from "@/device/models"
|
|
8
|
+
import {
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
type CSSProperties,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
} from "react"
|
|
16
|
+
|
|
17
|
+
import { addonRegistry } from "virtual:sireno/addons/registry"
|
|
18
|
+
import { uiOverrides } from "virtual:sireno/themes/manifest"
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
isSystemButton,
|
|
22
|
+
renderOverlayToggleButton,
|
|
23
|
+
renderSystemButton,
|
|
24
|
+
} from "@/deck/system-buttons/registry"
|
|
25
|
+
import {
|
|
26
|
+
ButtonFrame,
|
|
27
|
+
SPA_DOUBLE_TAP_DELAY_MS,
|
|
28
|
+
SPA_HOLD_DELAY_MS,
|
|
29
|
+
SplitActionSurface,
|
|
30
|
+
useAddonChannel,
|
|
31
|
+
type AddonGestureEvent,
|
|
32
|
+
} from "@sirenodeck/sirenodeck"
|
|
33
|
+
import { useButtonAction } from "../bridge/use-button-action"
|
|
34
|
+
import { ErrorBoundary } from "./ErrorBoundary"
|
|
35
|
+
|
|
36
|
+
// ponytail: the pomodoro addon's frontend subscribes to its
|
|
37
|
+
// `pomodoro:state` channel through this injected hook. Without it, the
|
|
38
|
+
// addon's hook falls back to a no-op and the countdown never renders.
|
|
39
|
+
// Set once at module load — `useAddonChannel` from the host uses the
|
|
40
|
+
// singleton `ChannelRegistry`, so the addon's components pick up state
|
|
41
|
+
// updates the same way built-in addons do.
|
|
42
|
+
;(
|
|
43
|
+
globalThis as { __pomodoroUseAddonChannel?: typeof useAddonChannel }
|
|
44
|
+
).__pomodoroUseAddonChannel = useAddonChannel
|
|
45
|
+
;(
|
|
46
|
+
globalThis as { __codingAgentsUseAddonChannel?: typeof useAddonChannel }
|
|
47
|
+
).__codingAgentsUseAddonChannel = useAddonChannel
|
|
48
|
+
|
|
49
|
+
const BUTTON_SIZE = BUTTON_SIZE_PX
|
|
50
|
+
export interface DeckButton {
|
|
51
|
+
id: string
|
|
52
|
+
type: string
|
|
53
|
+
label?: string
|
|
54
|
+
position?: number
|
|
55
|
+
config?: Record<string, unknown>
|
|
56
|
+
addonName?: string
|
|
57
|
+
frontendEntry?: string
|
|
58
|
+
full?: boolean
|
|
59
|
+
variant?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface Deck {
|
|
63
|
+
id: string
|
|
64
|
+
name: string
|
|
65
|
+
buttons: DeckButton[]
|
|
66
|
+
buttonColor?:
|
|
67
|
+
| "blue"
|
|
68
|
+
| "green"
|
|
69
|
+
| "purple"
|
|
70
|
+
| "cyan"
|
|
71
|
+
| "magenta"
|
|
72
|
+
| "amber"
|
|
73
|
+
| "lime"
|
|
74
|
+
variant?: string
|
|
75
|
+
hasOverlayDeckAvailable?: boolean
|
|
76
|
+
overlayDeckIcon?: string | null
|
|
77
|
+
overlayDeckName?: string | null
|
|
78
|
+
buttonErrors?: Array<{
|
|
79
|
+
position: number
|
|
80
|
+
expiresAt: number
|
|
81
|
+
buttonId?: string
|
|
82
|
+
details?: string
|
|
83
|
+
}>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface DeckProps {
|
|
87
|
+
readonly deck: Deck & { isCompact?: boolean }
|
|
88
|
+
readonly deviceModel: DeviceModelSpec
|
|
89
|
+
readonly gap?: number
|
|
90
|
+
readonly compact?: boolean
|
|
91
|
+
readonly children?: ReactNode
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const resolvePosition = (button: DeckButton, fallback: number): number => {
|
|
95
|
+
if (
|
|
96
|
+
typeof button.position === "number" &&
|
|
97
|
+
Number.isFinite(button.position) &&
|
|
98
|
+
button.position >= 0
|
|
99
|
+
) {
|
|
100
|
+
return button.position
|
|
101
|
+
}
|
|
102
|
+
return fallback
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface ButtonSurfaceProps {
|
|
106
|
+
readonly button: DeckButton
|
|
107
|
+
readonly deckOverlayIcon?: string | null
|
|
108
|
+
readonly overlayDeckName?: string | null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface DeckButtonCellProps {
|
|
112
|
+
readonly deckId: string
|
|
113
|
+
readonly position: number
|
|
114
|
+
readonly button: DeckButton
|
|
115
|
+
readonly col: number
|
|
116
|
+
readonly row: number
|
|
117
|
+
readonly splitAction?: boolean
|
|
118
|
+
readonly isError?: boolean
|
|
119
|
+
readonly buttonColor?:
|
|
120
|
+
| "blue"
|
|
121
|
+
| "green"
|
|
122
|
+
| "purple"
|
|
123
|
+
| "cyan"
|
|
124
|
+
| "magenta"
|
|
125
|
+
| "amber"
|
|
126
|
+
| "lime"
|
|
127
|
+
readonly variant?: string
|
|
128
|
+
readonly overlayDeckIcon?: string | null
|
|
129
|
+
readonly overlayDeckName?: string | null
|
|
130
|
+
readonly buttonErrors?: Deck["buttonErrors"]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const DeckButtonCell = ({
|
|
134
|
+
deckId,
|
|
135
|
+
position,
|
|
136
|
+
button,
|
|
137
|
+
col,
|
|
138
|
+
row,
|
|
139
|
+
splitAction = false,
|
|
140
|
+
isError = false,
|
|
141
|
+
buttonColor,
|
|
142
|
+
variant,
|
|
143
|
+
overlayDeckIcon: deckOverlayIcon,
|
|
144
|
+
overlayDeckName,
|
|
145
|
+
buttonErrors,
|
|
146
|
+
}: DeckButtonCellProps) => {
|
|
147
|
+
const { fire } = useButtonAction(deckId, position)
|
|
148
|
+
const pendingTapTimerRef = useRef<number | null>(null)
|
|
149
|
+
const holdTimerRef = useRef<number | null>(null)
|
|
150
|
+
const holdFiredRef = useRef(false)
|
|
151
|
+
const clearHoldTimer = () => {
|
|
152
|
+
if (holdTimerRef.current !== null) {
|
|
153
|
+
window.clearTimeout(holdTimerRef.current)
|
|
154
|
+
holdTimerRef.current = null
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
useEffect(
|
|
158
|
+
() => () => {
|
|
159
|
+
clearHoldTimer()
|
|
160
|
+
if (pendingTapTimerRef.current !== null) {
|
|
161
|
+
window.clearTimeout(pendingTapTimerRef.current)
|
|
162
|
+
pendingTapTimerRef.current = null
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
[],
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
const handlePointerDown = () => {
|
|
169
|
+
clearHoldTimer()
|
|
170
|
+
holdFiredRef.current = false
|
|
171
|
+
holdTimerRef.current = window.setTimeout(() => {
|
|
172
|
+
holdTimerRef.current = null
|
|
173
|
+
holdFiredRef.current = true
|
|
174
|
+
fire("hold")
|
|
175
|
+
}, SPA_HOLD_DELAY_MS)
|
|
176
|
+
}
|
|
177
|
+
const handlePointerUp = () => {
|
|
178
|
+
clearHoldTimer()
|
|
179
|
+
if (holdFiredRef.current) {
|
|
180
|
+
holdFiredRef.current = false
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
if (pendingTapTimerRef.current !== null) {
|
|
184
|
+
window.clearTimeout(pendingTapTimerRef.current)
|
|
185
|
+
pendingTapTimerRef.current = null
|
|
186
|
+
fire("dbl-tap")
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
pendingTapTimerRef.current = window.setTimeout(() => {
|
|
190
|
+
pendingTapTimerRef.current = null
|
|
191
|
+
fire("tap")
|
|
192
|
+
}, SPA_DOUBLE_TAP_DELAY_MS)
|
|
193
|
+
}
|
|
194
|
+
const handlePointerLeave = () => {
|
|
195
|
+
clearHoldTimer()
|
|
196
|
+
holdFiredRef.current = false
|
|
197
|
+
}
|
|
198
|
+
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
199
|
+
// Pointer clicks are handled on pointerup; detail 0 is keyboard activation.
|
|
200
|
+
if (event.detail === 0) fire("tap")
|
|
201
|
+
}
|
|
202
|
+
const gestureProps = {
|
|
203
|
+
onClick: handleClick,
|
|
204
|
+
onPointerDown: handlePointerDown,
|
|
205
|
+
onPointerUp: handlePointerUp,
|
|
206
|
+
onPointerLeave: handlePointerLeave,
|
|
207
|
+
onPointerCancel: handlePointerLeave,
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ponytail: per-button variant from user config beats deck-level
|
|
211
|
+
// variant (which beats the legacy `buttonColor` enum). Unknown names
|
|
212
|
+
// fall back to "default" at the ButtonFrame layer.
|
|
213
|
+
const effectiveVariant =
|
|
214
|
+
button.variant ?? variant ?? button.buttonColor ?? buttonColor ?? "default"
|
|
215
|
+
|
|
216
|
+
if (isError) {
|
|
217
|
+
return (
|
|
218
|
+
<div
|
|
219
|
+
style={{
|
|
220
|
+
gridColumn: col,
|
|
221
|
+
gridRow: row,
|
|
222
|
+
width: BUTTON_SIZE,
|
|
223
|
+
height: BUTTON_SIZE,
|
|
224
|
+
}}
|
|
225
|
+
data-button-type="core:temporary-error"
|
|
226
|
+
>
|
|
227
|
+
<ButtonFrame
|
|
228
|
+
buttonType="core:temporary-error"
|
|
229
|
+
variant="error"
|
|
230
|
+
{...gestureProps}
|
|
231
|
+
>
|
|
232
|
+
{renderSystemButton(
|
|
233
|
+
"core:temporary-error",
|
|
234
|
+
undefined,
|
|
235
|
+
(buttonErrors ?? []).find((e) => e.position === position)?.details,
|
|
236
|
+
)}
|
|
237
|
+
</ButtonFrame>
|
|
238
|
+
</div>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
if (splitAction) {
|
|
242
|
+
const overlayIcon = deckOverlayIcon ?? undefined
|
|
243
|
+
return (
|
|
244
|
+
<div
|
|
245
|
+
style={{
|
|
246
|
+
gridColumn: col,
|
|
247
|
+
gridRow: row,
|
|
248
|
+
width: BUTTON_SIZE,
|
|
249
|
+
height: BUTTON_SIZE,
|
|
250
|
+
}}
|
|
251
|
+
data-button-type={button.type}
|
|
252
|
+
data-split-action="true"
|
|
253
|
+
>
|
|
254
|
+
<ButtonFrame
|
|
255
|
+
buttonType={button.type}
|
|
256
|
+
variant={effectiveVariant}
|
|
257
|
+
{...gestureProps}
|
|
258
|
+
>
|
|
259
|
+
<SplitActionSurface
|
|
260
|
+
primary={renderSystemButton(button.type)}
|
|
261
|
+
secondary={renderSystemButton(
|
|
262
|
+
"core:overlay-toggle",
|
|
263
|
+
overlayIcon,
|
|
264
|
+
undefined,
|
|
265
|
+
overlayDeckName ?? undefined,
|
|
266
|
+
)}
|
|
267
|
+
/>
|
|
268
|
+
</ButtonFrame>
|
|
269
|
+
</div>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
if (button.full === true) {
|
|
273
|
+
return (
|
|
274
|
+
<div
|
|
275
|
+
style={{
|
|
276
|
+
gridColumn: col,
|
|
277
|
+
gridRow: row,
|
|
278
|
+
width: BUTTON_SIZE,
|
|
279
|
+
height: BUTTON_SIZE,
|
|
280
|
+
}}
|
|
281
|
+
data-button-type={button.type}
|
|
282
|
+
data-full="true"
|
|
283
|
+
>
|
|
284
|
+
<ErrorBoundary resetKey={button.id}>
|
|
285
|
+
<ButtonSurface
|
|
286
|
+
button={button}
|
|
287
|
+
deckOverlayIcon={deckOverlayIcon ?? null}
|
|
288
|
+
overlayDeckName={overlayDeckName ?? null}
|
|
289
|
+
/>
|
|
290
|
+
</ErrorBoundary>
|
|
291
|
+
</div>
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
return (
|
|
295
|
+
<div
|
|
296
|
+
style={{
|
|
297
|
+
gridColumn: col,
|
|
298
|
+
gridRow: row,
|
|
299
|
+
width: BUTTON_SIZE,
|
|
300
|
+
height: BUTTON_SIZE,
|
|
301
|
+
}}
|
|
302
|
+
data-button-type={button.type}
|
|
303
|
+
>
|
|
304
|
+
<ButtonFrame
|
|
305
|
+
buttonType={button.type}
|
|
306
|
+
variant={effectiveVariant}
|
|
307
|
+
{...gestureProps}
|
|
308
|
+
>
|
|
309
|
+
<ErrorBoundary resetKey={button.id}>
|
|
310
|
+
<ButtonSurface
|
|
311
|
+
button={button}
|
|
312
|
+
deckOverlayIcon={deckOverlayIcon ?? null}
|
|
313
|
+
overlayDeckName={overlayDeckName ?? null}
|
|
314
|
+
/>
|
|
315
|
+
</ErrorBoundary>
|
|
316
|
+
</ButtonFrame>
|
|
317
|
+
</div>
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Per-button addon surface. Subscribes to the per-button gesture channel and
|
|
323
|
+
* holds the latest gesture in state. The gesture value is replaced on each
|
|
324
|
+
* incoming event and never auto-cleared, so addons can compare against
|
|
325
|
+
* `gesture.at` in a `useEffect` without losing the hide-timer race.
|
|
326
|
+
*/
|
|
327
|
+
const ButtonSurface = ({
|
|
328
|
+
button,
|
|
329
|
+
deckOverlayIcon,
|
|
330
|
+
overlayDeckName,
|
|
331
|
+
}: ButtonSurfaceProps) => {
|
|
332
|
+
const registryEntry = addonRegistry[button.type]
|
|
333
|
+
const [gesture, setGesture] = useState<AddonGestureEvent | null>(null)
|
|
334
|
+
const channel = `runtime:gesture:${button.id}`
|
|
335
|
+
const { data } = useAddonChannel<AddonGestureEvent>(channel)
|
|
336
|
+
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
if (data !== undefined) setGesture(data)
|
|
339
|
+
}, [data])
|
|
340
|
+
|
|
341
|
+
if (isSystemButton(button.type)) {
|
|
342
|
+
if (
|
|
343
|
+
button.type === "core:overlay-toggle" &&
|
|
344
|
+
typeof deckOverlayIcon === "string" &&
|
|
345
|
+
deckOverlayIcon.length > 0
|
|
346
|
+
) {
|
|
347
|
+
return renderOverlayToggleButton(
|
|
348
|
+
deckOverlayIcon,
|
|
349
|
+
overlayDeckName ?? undefined,
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
return renderSystemButton(button.type)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (registryEntry === undefined) return null
|
|
356
|
+
const Component = registryEntry.Component
|
|
357
|
+
return (
|
|
358
|
+
<Component
|
|
359
|
+
config={button.config ?? {}}
|
|
360
|
+
state={null}
|
|
361
|
+
buttonType={button.type}
|
|
362
|
+
buttonId={button.id}
|
|
363
|
+
addonName={registryEntry.addonName}
|
|
364
|
+
gesture={gesture}
|
|
365
|
+
/>
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export const Deck = ({
|
|
370
|
+
deck,
|
|
371
|
+
deviceModel,
|
|
372
|
+
gap,
|
|
373
|
+
compact: compactOverride,
|
|
374
|
+
children,
|
|
375
|
+
}: DeckProps) => {
|
|
376
|
+
const model = deviceModel
|
|
377
|
+
const { columns, rows } = gridForKeyCount(model.keyCount)
|
|
378
|
+
const compact = compactOverride ?? deck.isCompact ?? false
|
|
379
|
+
const resolvedGap = compact ? 0 : (gap ?? DECK_GAP_PX)
|
|
380
|
+
const pad = compact ? 0 : DECK_PADDING_PX
|
|
381
|
+
const width = columns * BUTTON_SIZE + (columns - 1) * resolvedGap + pad * 2
|
|
382
|
+
const height = rows * BUTTON_SIZE + (rows - 1) * resolvedGap + pad * 2
|
|
383
|
+
const n1Position = model.keyCount - 1
|
|
384
|
+
const splitAtN1 = deck.hasOverlayDeckAvailable === true
|
|
385
|
+
const errorPositions = new Set(
|
|
386
|
+
(deck.buttonErrors ?? []).map((error) => error.position),
|
|
387
|
+
)
|
|
388
|
+
/**
|
|
389
|
+
* Theme-supplied deck-chrome background. Themes can paint a full-deck
|
|
390
|
+
* perspective grid (or any other background) by exporting a
|
|
391
|
+
* `deckBackground` fn from their ui-overrides module. Default is
|
|
392
|
+
* bg-neutral-950 — unchanged when no hook is registered.
|
|
393
|
+
*/
|
|
394
|
+
const extras = useMemo(() => {
|
|
395
|
+
const overrides = uiOverrides as {
|
|
396
|
+
deckBackground?: (props: { className: string }) => string | undefined
|
|
397
|
+
} | null
|
|
398
|
+
const hook = overrides?.deckBackground
|
|
399
|
+
if (typeof hook !== "function") return ""
|
|
400
|
+
return (
|
|
401
|
+
hook({ className: `bg-neutral-950 ${compact ? "p-0" : "p-4"}` }) ?? ""
|
|
402
|
+
)
|
|
403
|
+
}, [compact])
|
|
404
|
+
const baseClass = `grid rounded-xl ${compact ? "p-0" : "p-4"}`
|
|
405
|
+
const deckClass =
|
|
406
|
+
extras.length > 0 ? `${baseClass} ${extras}` : `${baseClass} bg-neutral-950`
|
|
407
|
+
|
|
408
|
+
// ponytail: positions without a button render a faint outline (emulator /
|
|
409
|
+
// browser only, not the hardware screenshot).
|
|
410
|
+
const occupiedPositions = new Set(
|
|
411
|
+
deck.buttons
|
|
412
|
+
.map((b, idx) => resolvePosition(b, idx))
|
|
413
|
+
.filter((p) => p < model.keyCount),
|
|
414
|
+
)
|
|
415
|
+
const emptyCells: ReactNode[] = []
|
|
416
|
+
if (!compact) {
|
|
417
|
+
for (let position = 0; position < model.keyCount; position += 1) {
|
|
418
|
+
if (occupiedPositions.has(position)) continue
|
|
419
|
+
const col = (position % columns) + 1
|
|
420
|
+
const row = Math.floor(position / columns) + 1
|
|
421
|
+
emptyCells.push(
|
|
422
|
+
<div
|
|
423
|
+
key={`empty-${position}`}
|
|
424
|
+
data-empty-cell="true"
|
|
425
|
+
aria-hidden="true"
|
|
426
|
+
className="rounded-2xl border border-solid opacity-30"
|
|
427
|
+
style={{
|
|
428
|
+
gridColumn: col,
|
|
429
|
+
gridRow: row,
|
|
430
|
+
width: BUTTON_SIZE,
|
|
431
|
+
height: BUTTON_SIZE,
|
|
432
|
+
borderColor: "var(--sireno-variant-default-border)",
|
|
433
|
+
}}
|
|
434
|
+
/>,
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return (
|
|
440
|
+
<div
|
|
441
|
+
className={deckClass}
|
|
442
|
+
style={
|
|
443
|
+
{
|
|
444
|
+
gridTemplateColumns: `repeat(${columns}, ${BUTTON_SIZE}px)`,
|
|
445
|
+
gridTemplateRows: `repeat(${rows}, ${BUTTON_SIZE}px)`,
|
|
446
|
+
gap: `${resolvedGap}px`,
|
|
447
|
+
width,
|
|
448
|
+
height,
|
|
449
|
+
} as CSSProperties
|
|
450
|
+
}
|
|
451
|
+
data-deck-id={deck.id}
|
|
452
|
+
data-columns={columns}
|
|
453
|
+
data-rows={rows}
|
|
454
|
+
>
|
|
455
|
+
{deck.buttons.map((button, idx) => {
|
|
456
|
+
const position = resolvePosition(button, idx)
|
|
457
|
+
if (position >= model.keyCount) return null
|
|
458
|
+
const col = (position % columns) + 1
|
|
459
|
+
const row = Math.floor(position / columns) + 1
|
|
460
|
+
const splitAction =
|
|
461
|
+
splitAtN1 &&
|
|
462
|
+
position === n1Position &&
|
|
463
|
+
(button.type === "core:back" || button.type === "core:settings-entry")
|
|
464
|
+
return (
|
|
465
|
+
<DeckButtonCell
|
|
466
|
+
key={button.id}
|
|
467
|
+
deckId={deck.id}
|
|
468
|
+
position={position}
|
|
469
|
+
button={button}
|
|
470
|
+
col={col}
|
|
471
|
+
row={row}
|
|
472
|
+
isError={errorPositions.has(position)}
|
|
473
|
+
buttonColor={deck.buttonColor}
|
|
474
|
+
variant={deck.variant}
|
|
475
|
+
overlayDeckIcon={deck.overlayDeckIcon ?? null}
|
|
476
|
+
overlayDeckName={deck.overlayDeckName ?? null}
|
|
477
|
+
buttonErrors={deck.buttonErrors}
|
|
478
|
+
{...(splitAction ? { splitAction: true } : {})}
|
|
479
|
+
/>
|
|
480
|
+
)
|
|
481
|
+
})}
|
|
482
|
+
{!compact && emptyCells}
|
|
483
|
+
{children}
|
|
484
|
+
</div>
|
|
485
|
+
)
|
|
486
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ConnectionStatus } from "../bridge/client"
|
|
2
|
+
|
|
3
|
+
export interface DisconnectedOverlayProps {
|
|
4
|
+
readonly status: ConnectionStatus
|
|
5
|
+
readonly disconnectedSince: number | null
|
|
6
|
+
readonly attempt: number
|
|
7
|
+
readonly lastError: string | null
|
|
8
|
+
readonly now: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const formatElapsed = (ms: number): string => {
|
|
12
|
+
const totalSeconds = Math.floor(ms / 1000)
|
|
13
|
+
const minutes = Math.floor(totalSeconds / 60)
|
|
14
|
+
const seconds = totalSeconds % 60
|
|
15
|
+
return `${minutes.toString().padStart(2, "0")}:${seconds
|
|
16
|
+
.toString()
|
|
17
|
+
.padStart(2, "0")}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const statusText = (status: ConnectionStatus, attempt: number): string => {
|
|
21
|
+
if (status === "failed")
|
|
22
|
+
return `Failed to reconnect after ${attempt} attempts`
|
|
23
|
+
if (status === "closed") return "Disconnected"
|
|
24
|
+
if (status === "connecting") return "Connecting…"
|
|
25
|
+
return status
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const DisconnectedOverlay = ({
|
|
29
|
+
status,
|
|
30
|
+
disconnectedSince,
|
|
31
|
+
attempt,
|
|
32
|
+
lastError,
|
|
33
|
+
now,
|
|
34
|
+
}: DisconnectedOverlayProps) => {
|
|
35
|
+
if (
|
|
36
|
+
status === "open" ||
|
|
37
|
+
status === "authorization-failed" ||
|
|
38
|
+
disconnectedSince === null
|
|
39
|
+
)
|
|
40
|
+
return null
|
|
41
|
+
const elapsed = now - disconnectedSince
|
|
42
|
+
if (elapsed < 30000) return null
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
data-testid="disconnected-overlay"
|
|
46
|
+
className="fixed inset-0 z-50 flex items-center justify-center bg-neutral-950/90 backdrop-blur"
|
|
47
|
+
>
|
|
48
|
+
<div className="w-full max-w-md rounded-xl border border-red-500/40 bg-neutral-900/95 p-8 text-center shadow-2xl">
|
|
49
|
+
<h2 className="mb-2 text-2xl font-semibold text-red-400">
|
|
50
|
+
Connection lost
|
|
51
|
+
</h2>
|
|
52
|
+
<p className="mb-6 text-sm text-neutral-400">
|
|
53
|
+
{statusText(status, attempt)}
|
|
54
|
+
</p>
|
|
55
|
+
<dl className="space-y-2 text-left text-sm">
|
|
56
|
+
<div className="flex justify-between">
|
|
57
|
+
<dt className="text-neutral-500">Status</dt>
|
|
58
|
+
<dd className="font-mono text-neutral-200">{status}</dd>
|
|
59
|
+
</div>
|
|
60
|
+
<div className="flex justify-between">
|
|
61
|
+
<dt className="text-neutral-500">Reconnect attempts</dt>
|
|
62
|
+
<dd className="font-mono text-neutral-200">{attempt}</dd>
|
|
63
|
+
</div>
|
|
64
|
+
{lastError !== null && (
|
|
65
|
+
<div className="flex justify-between">
|
|
66
|
+
<dt className="text-neutral-500">Last error</dt>
|
|
67
|
+
<dd className="truncate font-mono text-neutral-200">
|
|
68
|
+
{lastError}
|
|
69
|
+
</dd>
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
<div className="flex justify-between">
|
|
73
|
+
<dt className="text-neutral-500">Elapsed</dt>
|
|
74
|
+
<dd className="font-mono text-neutral-200">
|
|
75
|
+
{formatElapsed(elapsed)}
|
|
76
|
+
</dd>
|
|
77
|
+
</div>
|
|
78
|
+
</dl>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Component, type ErrorInfo, type ReactNode } from "react"
|
|
2
|
+
import { Icon } from "@sirenodeck/sirenodeck"
|
|
3
|
+
|
|
4
|
+
interface ErrorBoundaryProps {
|
|
5
|
+
readonly children: ReactNode
|
|
6
|
+
readonly onError?: (error: Error, info: ErrorInfo) => void
|
|
7
|
+
readonly resetKey?: string | number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ErrorBoundaryState {
|
|
11
|
+
readonly error: Error | null
|
|
12
|
+
readonly info: ErrorInfo | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Catches render errors in the deck tree and displays a fallback surface on
|
|
17
|
+
* each button position. Without this, a single broken addon's React render
|
|
18
|
+
* unmounts the whole tree and the emulator continues taking screenshots of
|
|
19
|
+
* a blank page with no log signal.
|
|
20
|
+
*
|
|
21
|
+
* Self-recovers via Vite's `import.meta.hot` API when present — once the
|
|
22
|
+
* developer fixes the broken module, HMR updates the parent and the boundary
|
|
23
|
+
* resets itself without a full page reload.
|
|
24
|
+
*/
|
|
25
|
+
export class ErrorBoundary extends Component<
|
|
26
|
+
ErrorBoundaryProps,
|
|
27
|
+
ErrorBoundaryState
|
|
28
|
+
> {
|
|
29
|
+
override state: ErrorBoundaryState = { error: null, info: null }
|
|
30
|
+
|
|
31
|
+
static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState> {
|
|
32
|
+
return { error }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override componentDidCatch(error: Error, info: ErrorInfo): void {
|
|
36
|
+
this.setState({ error, info })
|
|
37
|
+
this.props.onError?.(error, info)
|
|
38
|
+
if (typeof console !== "undefined") {
|
|
39
|
+
console.error(
|
|
40
|
+
"[ErrorBoundary] React render error:",
|
|
41
|
+
error,
|
|
42
|
+
info.componentStack,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override componentDidUpdate(prev: ErrorBoundaryProps): void {
|
|
48
|
+
if (this.state.error !== null && prev.resetKey !== this.props.resetKey) {
|
|
49
|
+
this.setState({ error: null, info: null })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override render(): ReactNode {
|
|
54
|
+
const { error } = this.state
|
|
55
|
+
if (error === null) return this.props.children
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className="flex h-full w-full flex-col items-center justify-center gap-1.5 p-1.5 text-center"
|
|
60
|
+
data-sireno-error-boundary="true"
|
|
61
|
+
>
|
|
62
|
+
<Icon source="icon://alert-circle" size={28} tone="danger" />
|
|
63
|
+
<span className="font-mono text-xs font-bold uppercase tracking-wide text-danger">
|
|
64
|
+
HMR error
|
|
65
|
+
</span>
|
|
66
|
+
<span className="font-mono text-[11px] leading-tight break-words opacity-80">
|
|
67
|
+
{String(error.message)}
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* HMR-aware hook that swaps a `resetKey` whenever Vite invalidates a module,
|
|
76
|
+
* forcing any mounted `ErrorBoundary` to re-render fresh instead of staying
|
|
77
|
+
* in the error state.
|
|
78
|
+
*
|
|
79
|
+
* Returns a stable `resetKey` value that updates when the importer is
|
|
80
|
+
* re-evaluated.
|
|
81
|
+
*/
|
|
82
|
+
export const useHmrResetKey = (): string => {
|
|
83
|
+
if (typeof import.meta === "undefined") return "stable"
|
|
84
|
+
const hot = (import.meta as { hot?: { data?: Record<string, unknown> } }).hot
|
|
85
|
+
if (hot === undefined) return "stable"
|
|
86
|
+
const data = (hot.data ?? (hot.data = {})) as Record<string, unknown>
|
|
87
|
+
const existing = data["resetKey"]
|
|
88
|
+
if (typeof existing === "string") return existing
|
|
89
|
+
const generated: string = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
90
|
+
data["resetKey"] = generated
|
|
91
|
+
return generated
|
|
92
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ConnectionStatus } from "../bridge/client"
|
|
2
|
+
|
|
3
|
+
export interface ReconnectingBannerProps {
|
|
4
|
+
readonly status: ConnectionStatus
|
|
5
|
+
readonly disconnectedSince: number | null
|
|
6
|
+
readonly attempt: number
|
|
7
|
+
readonly now: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const formatSeconds = (ms: number): string =>
|
|
11
|
+
`${Math.floor(ms / 1000).toString()}s`
|
|
12
|
+
|
|
13
|
+
export const ReconnectingBanner = ({
|
|
14
|
+
status,
|
|
15
|
+
disconnectedSince,
|
|
16
|
+
attempt,
|
|
17
|
+
now,
|
|
18
|
+
}: ReconnectingBannerProps) => {
|
|
19
|
+
if (
|
|
20
|
+
status === "open" ||
|
|
21
|
+
status === "authorization-failed" ||
|
|
22
|
+
disconnectedSince === null
|
|
23
|
+
)
|
|
24
|
+
return null
|
|
25
|
+
const elapsed = now - disconnectedSince
|
|
26
|
+
if (elapsed >= 30000) return null
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
data-testid="reconnecting-banner"
|
|
30
|
+
className="pointer-events-none fixed inset-0 z-50 flex items-center justify-center"
|
|
31
|
+
>
|
|
32
|
+
<div className="pointer-events-auto max-w-md rounded-lg border border-amber-500/40 bg-amber-500/10 px-4 py-2 text-center text-amber-200 shadow-lg backdrop-blur">
|
|
33
|
+
<span className="font-medium">Reconnecting…</span>
|
|
34
|
+
<span className="ml-2 text-amber-300/80">
|
|
35
|
+
attempt {attempt} · {formatSeconds(elapsed)} elapsed
|
|
36
|
+
</span>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|