@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,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/src/assets/logo72x72.png" />
|
|
6
|
+
<title>sirenodeck</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body class="bg-neutral-950 text-neutral-100">
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "react"
|
|
2
|
+
import { Navigate, Route, Routes, useNavigate } from "react-router-dom"
|
|
3
|
+
import { token } from "virtual:sireno/token"
|
|
4
|
+
import {
|
|
5
|
+
activeTheme,
|
|
6
|
+
colorTokens,
|
|
7
|
+
typography,
|
|
8
|
+
uiOverrides,
|
|
9
|
+
} from "virtual:sireno/themes/manifest"
|
|
10
|
+
|
|
11
|
+
import { ChannelRegistry } from "sirenodeck/react"
|
|
12
|
+
import { ThemeProvider, type ThemeContextValue } from "@/themes/index"
|
|
13
|
+
import {
|
|
14
|
+
AssetCacheProvider,
|
|
15
|
+
ThemeUiPresentationProvider,
|
|
16
|
+
buildPresentation,
|
|
17
|
+
useAssetCacheMutations,
|
|
18
|
+
} from "@sirenodeck/sirenodeck"
|
|
19
|
+
import {
|
|
20
|
+
getDeviceModel,
|
|
21
|
+
isKnownDeviceModel,
|
|
22
|
+
resolveDeckGap,
|
|
23
|
+
type DeviceModelSpec,
|
|
24
|
+
} from "@/device/models"
|
|
25
|
+
import {
|
|
26
|
+
createWsClient,
|
|
27
|
+
type WsClient,
|
|
28
|
+
type ConnectionStatus,
|
|
29
|
+
} from "./bridge/client"
|
|
30
|
+
import { WebSocketProvider, type WebSocketSend } from "./bridge/ws-context"
|
|
31
|
+
import { Deck } from "./components/Deck"
|
|
32
|
+
import { ReconnectingBanner } from "./components/ReconnectingBanner"
|
|
33
|
+
import { DisconnectedOverlay } from "./components/DisconnectedOverlay"
|
|
34
|
+
|
|
35
|
+
interface DeckButton {
|
|
36
|
+
id: string
|
|
37
|
+
type: string
|
|
38
|
+
position?: number
|
|
39
|
+
config: Record<string, unknown>
|
|
40
|
+
icon?: string
|
|
41
|
+
label?: string
|
|
42
|
+
variant?: string
|
|
43
|
+
actions?: { tap?: string; dbltap?: string; hold?: string }
|
|
44
|
+
full?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ButtonErrorState {
|
|
48
|
+
position: number
|
|
49
|
+
expiresAt: number
|
|
50
|
+
buttonId?: string
|
|
51
|
+
details?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface DeckState {
|
|
55
|
+
id: string
|
|
56
|
+
name: string
|
|
57
|
+
buttons: DeckButton[]
|
|
58
|
+
isCompact?: boolean
|
|
59
|
+
hasOverlayDeckAvailable?: boolean
|
|
60
|
+
overlayDeckIcon?: string | null
|
|
61
|
+
overlayDeckName?: string | null
|
|
62
|
+
buttonErrors: ButtonErrorState[]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const EMPTY_DECK: DeckState = {
|
|
66
|
+
id: "",
|
|
67
|
+
name: "",
|
|
68
|
+
buttons: [],
|
|
69
|
+
isCompact: undefined,
|
|
70
|
+
hasOverlayDeckAvailable: false,
|
|
71
|
+
buttonErrors: [],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ENV_WS_URL = (import.meta.env.VITE_WS_URL ??
|
|
75
|
+
"ws://127.0.0.1:52937") as string
|
|
76
|
+
const ENV_WS_PROXY_URL = (import.meta.env.VITE_WS_PROXY_URL ?? "") as string
|
|
77
|
+
|
|
78
|
+
const resolvePortFromWindow = (): number | undefined => {
|
|
79
|
+
if (typeof window === "undefined") return undefined
|
|
80
|
+
return (window as unknown as { __SIRENO_PORT__?: number }).__SIRENO_PORT__
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const wsUrl = (): string => {
|
|
84
|
+
if (typeof window === "undefined") return ENV_WS_URL
|
|
85
|
+
// An explicit capture/debugging proxy is an endpoint, not a service bridge:
|
|
86
|
+
// retain its host instead of rewriting it to the page's current hostname.
|
|
87
|
+
if (ENV_WS_PROXY_URL.length > 0) return ENV_WS_PROXY_URL
|
|
88
|
+
// ponytail: use the page's current hostname so the WS bridge is reachable
|
|
89
|
+
// from whichever interface the browser used (LAN, Tailscale, VPN, etc.).
|
|
90
|
+
const hostname = window.location.hostname
|
|
91
|
+
const port = resolvePortFromWindow()
|
|
92
|
+
if (port !== undefined) return `ws://${hostname}:${port}`
|
|
93
|
+
try {
|
|
94
|
+
const parsed = new URL(ENV_WS_URL)
|
|
95
|
+
return `${parsed.protocol}//${hostname}:${parsed.port}${parsed.pathname}${parsed.search}`
|
|
96
|
+
} catch {
|
|
97
|
+
return ENV_WS_URL
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const buildThemeContext = (): ThemeContextValue => {
|
|
102
|
+
if (activeTheme) {
|
|
103
|
+
const manifestPath = activeTheme.manifestPath ?? ""
|
|
104
|
+
const themeDir = manifestPath.replace(/\/sirenodeck\.json$/, "")
|
|
105
|
+
return {
|
|
106
|
+
name: activeTheme.name,
|
|
107
|
+
cssPath: "",
|
|
108
|
+
theme: {
|
|
109
|
+
name: activeTheme.name,
|
|
110
|
+
apiVersion: 3,
|
|
111
|
+
source: { kind: "builtin" as const, resolvedPath: themeDir },
|
|
112
|
+
manifestPath,
|
|
113
|
+
uiOverridesPath: activeTheme.uiOverridesPath ?? null,
|
|
114
|
+
cssPath: "",
|
|
115
|
+
},
|
|
116
|
+
colorTokens,
|
|
117
|
+
typography,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
name: "default",
|
|
122
|
+
cssPath: "",
|
|
123
|
+
theme: {
|
|
124
|
+
name: "default",
|
|
125
|
+
apiVersion: 3,
|
|
126
|
+
source: { kind: "builtin" as const, resolvedPath: "" },
|
|
127
|
+
manifestPath: "",
|
|
128
|
+
uiOverridesPath: null,
|
|
129
|
+
cssPath: "",
|
|
130
|
+
},
|
|
131
|
+
colorTokens: null,
|
|
132
|
+
typography: null,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let _wsClientInitialized = false
|
|
136
|
+
|
|
137
|
+
export const App = () => {
|
|
138
|
+
const [theme] = useState<ThemeContextValue>(() => buildThemeContext())
|
|
139
|
+
const presentation = useMemo(() => buildPresentation(uiOverrides), [])
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<AssetCacheProvider>
|
|
143
|
+
<ThemeProvider value={theme}>
|
|
144
|
+
<ThemeUiPresentationProvider presentation={presentation}>
|
|
145
|
+
<AppContent />
|
|
146
|
+
</ThemeUiPresentationProvider>
|
|
147
|
+
</ThemeProvider>
|
|
148
|
+
</AssetCacheProvider>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
const AppContent = () => {
|
|
152
|
+
const [deck, setDeck] = useState<DeckState>(EMPTY_DECK)
|
|
153
|
+
const { setAsset } = useAssetCacheMutations()
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
const preview = (event: MessageEvent<unknown>): void => {
|
|
157
|
+
if (event.source !== window.parent) return
|
|
158
|
+
try {
|
|
159
|
+
if (new URL(event.origin).hostname !== window.location.hostname) return
|
|
160
|
+
} catch {
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
if (typeof event.data !== "object" || event.data === null) return
|
|
164
|
+
const message = event.data as {
|
|
165
|
+
type?: string
|
|
166
|
+
deckId?: string
|
|
167
|
+
index?: number
|
|
168
|
+
position?: number
|
|
169
|
+
type?: string
|
|
170
|
+
config?: Record<string, unknown>
|
|
171
|
+
appearance?: {
|
|
172
|
+
icon: string
|
|
173
|
+
label: string
|
|
174
|
+
variant: string
|
|
175
|
+
actions: { tap?: string; dbltap?: string; hold?: string }
|
|
176
|
+
}
|
|
177
|
+
assets?: Array<{ filename: string; preview: string }>
|
|
178
|
+
}
|
|
179
|
+
if (
|
|
180
|
+
message.type !== "editor-preview-config" ||
|
|
181
|
+
message.deckId === undefined ||
|
|
182
|
+
message.index === undefined ||
|
|
183
|
+
message.config === undefined
|
|
184
|
+
)
|
|
185
|
+
return
|
|
186
|
+
const previewAssetIds = new Map<string, string>()
|
|
187
|
+
for (const asset of message.assets ?? []) {
|
|
188
|
+
const id = `editor-preview-${asset.filename}`
|
|
189
|
+
previewAssetIds.set(`./assets/${asset.filename}`, id)
|
|
190
|
+
setAsset(id, asset.preview)
|
|
191
|
+
}
|
|
192
|
+
const applyPreviewAssets = (value: unknown): unknown => {
|
|
193
|
+
if (typeof value === "string") {
|
|
194
|
+
const id = previewAssetIds.get(value)
|
|
195
|
+
return id === undefined ? value : `asset://${id}`
|
|
196
|
+
}
|
|
197
|
+
if (Array.isArray(value)) return value.map(applyPreviewAssets)
|
|
198
|
+
if (typeof value === "object" && value !== null)
|
|
199
|
+
return Object.fromEntries(
|
|
200
|
+
Object.entries(value).map(([key, child]) => [
|
|
201
|
+
key,
|
|
202
|
+
applyPreviewAssets(child),
|
|
203
|
+
]),
|
|
204
|
+
)
|
|
205
|
+
return value
|
|
206
|
+
}
|
|
207
|
+
setDeck((current) => {
|
|
208
|
+
if (current.id !== message.deckId) return current
|
|
209
|
+
const position = message.position ?? message.index!
|
|
210
|
+
const existingIndex = current.buttons.findIndex(
|
|
211
|
+
(button, index) => (button.position ?? index) === position,
|
|
212
|
+
)
|
|
213
|
+
if (existingIndex === -1 && message.type === undefined) return current
|
|
214
|
+
return {
|
|
215
|
+
...current,
|
|
216
|
+
buttons:
|
|
217
|
+
existingIndex === -1
|
|
218
|
+
? [
|
|
219
|
+
...current.buttons,
|
|
220
|
+
{
|
|
221
|
+
id: `editor-preview-${position}`,
|
|
222
|
+
type: message.type!,
|
|
223
|
+
position,
|
|
224
|
+
config: applyPreviewAssets(message.config) as Record<
|
|
225
|
+
string,
|
|
226
|
+
unknown
|
|
227
|
+
>,
|
|
228
|
+
...message.appearance,
|
|
229
|
+
...(message.appearance?.icon
|
|
230
|
+
? {
|
|
231
|
+
icon: applyPreviewAssets(
|
|
232
|
+
message.appearance.icon,
|
|
233
|
+
) as string,
|
|
234
|
+
}
|
|
235
|
+
: {}),
|
|
236
|
+
},
|
|
237
|
+
]
|
|
238
|
+
: current.buttons.map((button, index) =>
|
|
239
|
+
index === existingIndex
|
|
240
|
+
? {
|
|
241
|
+
...button,
|
|
242
|
+
...message.appearance,
|
|
243
|
+
config: applyPreviewAssets(message.config) as Record<
|
|
244
|
+
string,
|
|
245
|
+
unknown
|
|
246
|
+
>,
|
|
247
|
+
...(message.appearance?.icon
|
|
248
|
+
? {
|
|
249
|
+
icon: applyPreviewAssets(
|
|
250
|
+
message.appearance.icon,
|
|
251
|
+
) as string,
|
|
252
|
+
}
|
|
253
|
+
: {}),
|
|
254
|
+
}
|
|
255
|
+
: button,
|
|
256
|
+
),
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
window.addEventListener("message", preview)
|
|
261
|
+
return () => window.removeEventListener("message", preview)
|
|
262
|
+
}, [setAsset])
|
|
263
|
+
const [send, setSend] = useState<WebSocketSend | null>(null)
|
|
264
|
+
const [connectionStatus, setConnectionStatus] =
|
|
265
|
+
useState<ConnectionStatus>("connecting")
|
|
266
|
+
const [disconnectedSince, setDisconnectedSince] = useState<number | null>(
|
|
267
|
+
null,
|
|
268
|
+
)
|
|
269
|
+
const [attempt, setAttempt] = useState(0)
|
|
270
|
+
const [lastError, setLastError] = useState<string | null>(null)
|
|
271
|
+
const [now, setNow] = useState(() => Date.now())
|
|
272
|
+
const [deviceModel, setDeviceModel] = useState<DeviceModelSpec>(() =>
|
|
273
|
+
getDeviceModel("mk2"),
|
|
274
|
+
)
|
|
275
|
+
// ponytail: block first paint until the WS `assets` message has been received
|
|
276
|
+
// and the asset cache is populated. Without this gate, the deck renders with
|
|
277
|
+
// an empty asset cache and shows the broken-icon fallback on cold-start.
|
|
278
|
+
const [assetsReady, setAssetsReady] = useState(false)
|
|
279
|
+
const clientRef = useRef<WsClient | null>(null)
|
|
280
|
+
const navigate = useNavigate()
|
|
281
|
+
const initialSearch = useRef(
|
|
282
|
+
typeof window === "undefined" ? "" : window.location.search,
|
|
283
|
+
).current
|
|
284
|
+
const compactParam = new URLSearchParams(initialSearch).get("compact")
|
|
285
|
+
const deckGap = resolveDeckGap(
|
|
286
|
+
new URLSearchParams(initialSearch).get("gap"),
|
|
287
|
+
false,
|
|
288
|
+
)
|
|
289
|
+
// ponytail: ignore the first `closed` after an `open` — happens during
|
|
290
|
+
// WS-replacement that some React navigations trigger (StrictMode /
|
|
291
|
+
// hot-reload / route transitions). The WS client reports the old socket's
|
|
292
|
+
// close, then the new one opens within milliseconds. Without this guard the
|
|
293
|
+
// banner pops on every deck change.
|
|
294
|
+
const lastStatusRef = useRef<ConnectionStatus | null>(null)
|
|
295
|
+
const reconnectLatchTimerRef = useRef<number | null>(null)
|
|
296
|
+
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
if (_wsClientInitialized) return
|
|
299
|
+
_wsClientInitialized = true
|
|
300
|
+
const url = wsUrl()
|
|
301
|
+
const client = createWsClient({
|
|
302
|
+
url,
|
|
303
|
+
...(token !== "" ? { token } : {}),
|
|
304
|
+
onStatus: (status) => {
|
|
305
|
+
const previous = lastStatusRef.current
|
|
306
|
+
lastStatusRef.current = status
|
|
307
|
+
setConnectionStatus(status)
|
|
308
|
+
setAttempt(client.getAttempt())
|
|
309
|
+
setLastError(client.getLastError())
|
|
310
|
+
if (status === "authorization-failed") {
|
|
311
|
+
setDisconnectedSince(Date.now())
|
|
312
|
+
return
|
|
313
|
+
}
|
|
314
|
+
if (status === "open") {
|
|
315
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
316
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
317
|
+
reconnectLatchTimerRef.current = null
|
|
318
|
+
}
|
|
319
|
+
setDisconnectedSince(null)
|
|
320
|
+
return
|
|
321
|
+
}
|
|
322
|
+
if (status === "connecting") {
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
if (status === "closed") {
|
|
326
|
+
if (previous === "open") {
|
|
327
|
+
// Short-lived close after an open connection is treated as
|
|
328
|
+
// transient noise — wait 500ms before latching. If a new
|
|
329
|
+
// connection opens before the timer fires, the latch is cancelled.
|
|
330
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
331
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
332
|
+
}
|
|
333
|
+
const openedAt = Date.now()
|
|
334
|
+
reconnectLatchTimerRef.current = window.setTimeout(() => {
|
|
335
|
+
reconnectLatchTimerRef.current = null
|
|
336
|
+
setDisconnectedSince((current) =>
|
|
337
|
+
current === null ? openedAt : current,
|
|
338
|
+
)
|
|
339
|
+
}, 500)
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
setDisconnectedSince((current) =>
|
|
343
|
+
current === null ? Date.now() : current,
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
onMessage: (message) => {
|
|
348
|
+
if (message.type === "hello-ack" && message.device !== undefined) {
|
|
349
|
+
const modelId = message.device.model
|
|
350
|
+
if (isKnownDeviceModel(modelId)) {
|
|
351
|
+
setDeviceModel(getDeviceModel(modelId))
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (message.type === "device-info") {
|
|
355
|
+
const modelId = message.device.model
|
|
356
|
+
if (isKnownDeviceModel(modelId)) {
|
|
357
|
+
setDeviceModel(getDeviceModel(modelId))
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (message.type === "assets") {
|
|
361
|
+
for (const asset of message.assets) {
|
|
362
|
+
setAsset(asset.id, asset.src)
|
|
363
|
+
}
|
|
364
|
+
setAssetsReady(true)
|
|
365
|
+
}
|
|
366
|
+
if (message.type === "deck-config") {
|
|
367
|
+
const surface = (
|
|
368
|
+
message.surfaces as Record<
|
|
369
|
+
string,
|
|
370
|
+
{
|
|
371
|
+
name?: string
|
|
372
|
+
buttons?: DeckButton[]
|
|
373
|
+
buttonColor?:
|
|
374
|
+
| "blue"
|
|
375
|
+
| "green"
|
|
376
|
+
| "purple"
|
|
377
|
+
| "cyan"
|
|
378
|
+
| "magenta"
|
|
379
|
+
| "amber"
|
|
380
|
+
| "lime"
|
|
381
|
+
variant?: string
|
|
382
|
+
buttonErrors?: ButtonErrorState[]
|
|
383
|
+
}
|
|
384
|
+
>
|
|
385
|
+
)[message.deckId]
|
|
386
|
+
if (surface && Array.isArray(surface.buttons)) {
|
|
387
|
+
navigate(`/decks/${message.deckId}${window.location.search}`, {
|
|
388
|
+
replace: true,
|
|
389
|
+
})
|
|
390
|
+
setDeck((previous) => ({
|
|
391
|
+
id: message.deckId,
|
|
392
|
+
name: surface.name ?? message.deckId,
|
|
393
|
+
buttons: surface.buttons,
|
|
394
|
+
...(surface.buttonColor !== undefined
|
|
395
|
+
? { buttonColor: surface.buttonColor }
|
|
396
|
+
: {}),
|
|
397
|
+
...(surface.variant !== undefined
|
|
398
|
+
? { variant: surface.variant }
|
|
399
|
+
: {}),
|
|
400
|
+
isCompact:
|
|
401
|
+
compactParam === "0" ? false : (message.isCompact ?? false),
|
|
402
|
+
hasOverlayDeckAvailable: message.hasOverlayDeckAvailable ?? false,
|
|
403
|
+
overlayDeckIcon: message.overlayDeckIcon ?? null,
|
|
404
|
+
overlayDeckName: message.overlayDeckName ?? null,
|
|
405
|
+
buttonErrors: Array.isArray(surface.buttonErrors)
|
|
406
|
+
? surface.buttonErrors
|
|
407
|
+
: [],
|
|
408
|
+
}))
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (message.type === "button-error") {
|
|
412
|
+
const position = message.position
|
|
413
|
+
const durationMs = message.durationMs ?? 5000
|
|
414
|
+
setDeck((previous) => {
|
|
415
|
+
// ponytail: drop errors for a deck we're no longer on — an
|
|
416
|
+
// in-flight action error arriving after navigation must not
|
|
417
|
+
// land on the new deck's buttons.
|
|
418
|
+
if (previous.id !== message.deckId) return previous
|
|
419
|
+
return {
|
|
420
|
+
...previous,
|
|
421
|
+
buttonErrors: [
|
|
422
|
+
...previous.buttonErrors.filter(
|
|
423
|
+
(error) => error.position !== position,
|
|
424
|
+
),
|
|
425
|
+
{
|
|
426
|
+
position,
|
|
427
|
+
expiresAt: Date.now() + durationMs,
|
|
428
|
+
...(typeof message.buttonId === "string"
|
|
429
|
+
? { buttonId: message.buttonId }
|
|
430
|
+
: {}),
|
|
431
|
+
...(typeof message.details === "string"
|
|
432
|
+
? { details: message.details }
|
|
433
|
+
: {}),
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
if (message.type === "state") {
|
|
440
|
+
for (const [channel, payload] of Object.entries(message.channels)) {
|
|
441
|
+
ChannelRegistry.instance().publish(channel, payload)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
})
|
|
446
|
+
clientRef.current = client
|
|
447
|
+
setSend(() => client.send)
|
|
448
|
+
client.connect()
|
|
449
|
+
ChannelRegistry.setAnnounceSubscribe((channels) =>
|
|
450
|
+
client.subscribeChannels(channels),
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
const timer = setInterval(() => {
|
|
454
|
+
setDeck((previous) => {
|
|
455
|
+
if (previous.buttonErrors.length === 0) return previous
|
|
456
|
+
const tickNow = Date.now()
|
|
457
|
+
const remaining = previous.buttonErrors.filter(
|
|
458
|
+
(error) => error.expiresAt > tickNow,
|
|
459
|
+
)
|
|
460
|
+
if (remaining.length === previous.buttonErrors.length) {
|
|
461
|
+
return previous
|
|
462
|
+
}
|
|
463
|
+
setNow(tickNow)
|
|
464
|
+
return { ...previous, buttonErrors: remaining }
|
|
465
|
+
})
|
|
466
|
+
}, 250)
|
|
467
|
+
|
|
468
|
+
return () => {
|
|
469
|
+
_wsClientInitialized = false
|
|
470
|
+
ChannelRegistry.setAnnounceSubscribe(null)
|
|
471
|
+
setSend(null)
|
|
472
|
+
client.close()
|
|
473
|
+
clearInterval(timer)
|
|
474
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
475
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
476
|
+
reconnectLatchTimerRef.current = null
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}, [setAsset, navigate])
|
|
480
|
+
|
|
481
|
+
return (
|
|
482
|
+
<WebSocketProvider value={send}>
|
|
483
|
+
<main className="bg-bg text-fg flex min-h-screen items-center justify-center">
|
|
484
|
+
<ReconnectingBanner
|
|
485
|
+
status={connectionStatus}
|
|
486
|
+
disconnectedSince={disconnectedSince}
|
|
487
|
+
attempt={attempt}
|
|
488
|
+
now={now}
|
|
489
|
+
/>
|
|
490
|
+
{connectionStatus === "authorization-failed" && (
|
|
491
|
+
<div
|
|
492
|
+
data-testid="authorization-failed"
|
|
493
|
+
className="fixed inset-0 z-50 flex items-center justify-center bg-neutral-950/95 p-6 text-center"
|
|
494
|
+
>
|
|
495
|
+
<p className="max-w-md text-sm text-neutral-200">
|
|
496
|
+
Authorization token changed. Close this window and run{" "}
|
|
497
|
+
<code className="font-mono text-sky-300">
|
|
498
|
+
sirenodeck config-ui
|
|
499
|
+
</code>{" "}
|
|
500
|
+
to get access again
|
|
501
|
+
</p>
|
|
502
|
+
</div>
|
|
503
|
+
)}
|
|
504
|
+
{assetsReady ? (
|
|
505
|
+
<Routes>
|
|
506
|
+
<Route
|
|
507
|
+
path="/decks/:deckId"
|
|
508
|
+
element={
|
|
509
|
+
<Deck
|
|
510
|
+
deck={deck}
|
|
511
|
+
deviceModel={deviceModel}
|
|
512
|
+
gap={deckGap}
|
|
513
|
+
compact={
|
|
514
|
+
compactParam === null ? undefined : compactParam === "1"
|
|
515
|
+
}
|
|
516
|
+
/>
|
|
517
|
+
}
|
|
518
|
+
/>
|
|
519
|
+
<Route path="*" element={<Navigate to="/decks/main" replace />} />
|
|
520
|
+
</Routes>
|
|
521
|
+
) : (
|
|
522
|
+
<div className="deck-loading" data-testid="deck-loading">
|
|
523
|
+
Loading…
|
|
524
|
+
</div>
|
|
525
|
+
)}
|
|
526
|
+
<DisconnectedOverlay
|
|
527
|
+
status={connectionStatus}
|
|
528
|
+
disconnectedSince={disconnectedSince}
|
|
529
|
+
attempt={attempt}
|
|
530
|
+
lastError={lastError}
|
|
531
|
+
now={now}
|
|
532
|
+
/>
|
|
533
|
+
</main>
|
|
534
|
+
</WebSocketProvider>
|
|
535
|
+
)
|
|
536
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "/* mock theme css for tests */"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
|
|
3
|
+
interface MockButtonFrameProps {
|
|
4
|
+
pressed?: boolean
|
|
5
|
+
isTapping?: boolean
|
|
6
|
+
isHolding?: boolean
|
|
7
|
+
holdProgress?: number
|
|
8
|
+
buttonType: string
|
|
9
|
+
variant?: "default" | "error"
|
|
10
|
+
onPointerDown?: () => void
|
|
11
|
+
onPointerUp?: () => void
|
|
12
|
+
onPointerLeave?: () => void
|
|
13
|
+
onClick?: () => void
|
|
14
|
+
onDoubleClick?: () => void
|
|
15
|
+
onContextMenu?: (e: React.MouseEvent) => void
|
|
16
|
+
children?: ReactNode
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MockButtonFrame = ({
|
|
20
|
+
pressed,
|
|
21
|
+
isTapping,
|
|
22
|
+
isHolding,
|
|
23
|
+
holdProgress,
|
|
24
|
+
buttonType,
|
|
25
|
+
variant = "default",
|
|
26
|
+
onPointerDown,
|
|
27
|
+
onPointerUp,
|
|
28
|
+
onPointerLeave,
|
|
29
|
+
onClick,
|
|
30
|
+
onDoubleClick,
|
|
31
|
+
onContextMenu,
|
|
32
|
+
children,
|
|
33
|
+
}: MockButtonFrameProps) => (
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
data-button-type={buttonType}
|
|
37
|
+
data-variant={variant}
|
|
38
|
+
data-pressed={pressed}
|
|
39
|
+
data-tapping={isTapping}
|
|
40
|
+
data-holding={isHolding}
|
|
41
|
+
data-hold-progress={holdProgress}
|
|
42
|
+
onPointerDown={onPointerDown}
|
|
43
|
+
onPointerUp={onPointerUp}
|
|
44
|
+
onPointerLeave={onPointerLeave}
|
|
45
|
+
onClick={onClick}
|
|
46
|
+
onDoubleClick={onDoubleClick}
|
|
47
|
+
onContextMenu={onContextMenu}
|
|
48
|
+
className="mock-button-frame"
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</button>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export const activeTheme = {
|
|
55
|
+
name: "default",
|
|
56
|
+
frontendPath: "/__mocks__/themes/default/index",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const components = {
|
|
60
|
+
Icon: () => null,
|
|
61
|
+
Label: () => null,
|
|
62
|
+
Text: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
|
|
63
|
+
TapIndicator: () => null,
|
|
64
|
+
Chip: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const surfaces = {
|
|
68
|
+
IconLabel: ({ label }: { label: string }) => <span>{label}</span>,
|
|
69
|
+
Bars: () => null,
|
|
70
|
+
LabelValueList: () => null,
|
|
71
|
+
SplitAction: () => null,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const primitives = {
|
|
75
|
+
ButtonFrame: MockButtonFrame,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default { activeTheme, components, surfaces, primitives }
|