@sirenodeck/sirenodeck 0.2.6 → 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 +403 -41501
- 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/run.ts +28 -1
- package/src/cli/commands/service-manager.ts +53 -1
- package/src/cli/commands/start.ts +17 -0
- package/src/cli/startup-display.ts +1 -1
- package/src/core/settings.ts +5 -3
- package/src/device/black-frame.ts +5 -14
- package/src/outputClient/real.ts +2 -0
- package/src/vite/virtual-modules.ts +16 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" class="h-full dark" data-theme="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="icon" type="image/png" href="/src/assets/logo72x72.png" />
|
|
7
|
+
<title>sirenodeck config UI</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body class="h-full font-sans">
|
|
10
|
+
<div id="root" class="h-full"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react"
|
|
2
|
+
import { ListBox, Select, Toast } from "@heroui/react"
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getDeviceModel,
|
|
6
|
+
isKnownDeviceModel,
|
|
7
|
+
deckDimensions,
|
|
8
|
+
DECK_GAP_PX,
|
|
9
|
+
type DeviceModelSpec,
|
|
10
|
+
} from "@/device/models"
|
|
11
|
+
|
|
12
|
+
import { token } from "virtual:sireno/token"
|
|
13
|
+
|
|
14
|
+
import { createWsClient, type WsClient, type WsStatus } from "./bridge"
|
|
15
|
+
import { DeckFrame } from "./DeckFrame"
|
|
16
|
+
import { Shell } from "./Shell"
|
|
17
|
+
import { BridgeLogsPage } from "./pages/BridgeLogsPage"
|
|
18
|
+
import { ServiceLogsPage } from "./pages/ServiceLogsPage"
|
|
19
|
+
import { AddonsPage, type AddonInventory } from "./pages/AddonsPage"
|
|
20
|
+
import { ConfigPage } from "./pages/ConfigPage"
|
|
21
|
+
import { DecksPage } from "./pages/DecksPage"
|
|
22
|
+
import { EditorPage, type EditorState } from "./pages/EditorPage"
|
|
23
|
+
import { AboutPage } from "./pages/AboutPage"
|
|
24
|
+
|
|
25
|
+
const ENV_WS_URL = (import.meta.env.VITE_WS_URL ??
|
|
26
|
+
"ws://127.0.0.1:52937") as string
|
|
27
|
+
const ENV_FRONTEND_URL = (import.meta.env.VITE_FRONTEND_URL ??
|
|
28
|
+
"http://127.0.0.1:5180") as string
|
|
29
|
+
const ENV_EMULATOR_MODE = import.meta.env.VITE_EMULATOR_MODE !== false
|
|
30
|
+
const ENV_DEV_MODE = import.meta.env.VITE_DEV_MODE === true
|
|
31
|
+
const ENV_REMOTE_MODE = import.meta.env.VITE_REMOTE_MODE === true
|
|
32
|
+
|
|
33
|
+
const VIRTUAL_DEVICE_IDS = ["mk2", "mini", "xl"] as const
|
|
34
|
+
|
|
35
|
+
const DEFAULT_DEVICE_MODEL = getDeviceModel("mk2")
|
|
36
|
+
|
|
37
|
+
interface DeviceSelectorProps {
|
|
38
|
+
readonly device: string
|
|
39
|
+
readonly onChange: (deviceId: string) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DeviceSelector = ({ device, onChange }: DeviceSelectorProps) => {
|
|
43
|
+
return (
|
|
44
|
+
<label className="flex shrink-0 items-center gap-2">
|
|
45
|
+
<span className="text-neutral-500">device</span>
|
|
46
|
+
<Select
|
|
47
|
+
selectedKey={device}
|
|
48
|
+
onSelectionChange={(key) => onChange(String(key))}
|
|
49
|
+
aria-label="device"
|
|
50
|
+
data-testid="top-device-selector"
|
|
51
|
+
>
|
|
52
|
+
<Select.Trigger className="min-h-8 bg-neutral-800 px-2 text-[11px]">
|
|
53
|
+
<Select.Value />
|
|
54
|
+
<Select.Indicator />
|
|
55
|
+
</Select.Trigger>
|
|
56
|
+
<Select.Popover>
|
|
57
|
+
<ListBox>
|
|
58
|
+
{VIRTUAL_DEVICE_IDS.map((id) => {
|
|
59
|
+
const model = getDeviceModel(id)
|
|
60
|
+
return (
|
|
61
|
+
<ListBox.Item key={id} id={id} textValue={model.name}>
|
|
62
|
+
{model.name}
|
|
63
|
+
<ListBox.ItemIndicator />
|
|
64
|
+
</ListBox.Item>
|
|
65
|
+
)
|
|
66
|
+
})}
|
|
67
|
+
</ListBox>
|
|
68
|
+
</Select.Popover>
|
|
69
|
+
</Select>
|
|
70
|
+
</label>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface AppProps {
|
|
75
|
+
readonly wsUrl?: string
|
|
76
|
+
readonly initialDeviceModel?: string
|
|
77
|
+
readonly initialSection?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const SECTIONS = [
|
|
81
|
+
"config",
|
|
82
|
+
"about",
|
|
83
|
+
...(ENV_DEV_MODE
|
|
84
|
+
? (["addons", "device", "bridge-logs", "service-logs", "decks"] as const)
|
|
85
|
+
: []),
|
|
86
|
+
] as const
|
|
87
|
+
|
|
88
|
+
const isValidSection = (s: string | null): s is (typeof SECTIONS)[number] =>
|
|
89
|
+
s !== null && (SECTIONS as ReadonlyArray<string>).includes(s)
|
|
90
|
+
|
|
91
|
+
export const App = ({
|
|
92
|
+
wsUrl = ENV_WS_URL,
|
|
93
|
+
initialDeviceModel,
|
|
94
|
+
initialSection = "config",
|
|
95
|
+
}: AppProps = {}): React.ReactElement => {
|
|
96
|
+
const [activeSection, setActiveSection] = useState<string>(initialSection)
|
|
97
|
+
const [deckOnly] = useState<boolean>(
|
|
98
|
+
() =>
|
|
99
|
+
typeof window !== "undefined" &&
|
|
100
|
+
new URLSearchParams(window.location.search).get("deckOnly") === "1",
|
|
101
|
+
)
|
|
102
|
+
const [connectionStatus, setConnectionStatus] =
|
|
103
|
+
useState<WsStatus>("connecting")
|
|
104
|
+
const [disconnectedSince, setDisconnectedSince] = useState<number | null>(
|
|
105
|
+
null,
|
|
106
|
+
)
|
|
107
|
+
const [deckScale, setDeckScale] = useState(1)
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
disconnectedSinceRef.current = disconnectedSince
|
|
110
|
+
}, [disconnectedSince])
|
|
111
|
+
const [attempt, setAttempt] = useState(0)
|
|
112
|
+
const [lastError, setLastError] = useState<string | null>(null)
|
|
113
|
+
const [now, setNow] = useState(() => Date.now())
|
|
114
|
+
const [deckId, setDeckId] = useState<string>("")
|
|
115
|
+
const [configView, setConfigView] = useState<"editor" | "config">("editor")
|
|
116
|
+
// ponytail: addon inventory arrives over the WS bridge as a follow-up
|
|
117
|
+
// to hello-ack (see protocol-internal.addonsInventoryMessageSchema).
|
|
118
|
+
// Receiving it here avoids the previous `/api/addons` fetch, which the
|
|
119
|
+
// start-mode daemon used to serve but isn't bound in --emulator mode.
|
|
120
|
+
const [addonInventory, setAddonInventory] = useState<AddonInventory | null>(
|
|
121
|
+
null,
|
|
122
|
+
)
|
|
123
|
+
const [deckTree, setDeckTree] = useState<{
|
|
124
|
+
rootId: string
|
|
125
|
+
decks: unknown[]
|
|
126
|
+
} | null>(null)
|
|
127
|
+
const [editorState, setEditorState] = useState<EditorState | null>(null)
|
|
128
|
+
const [editorResult, setEditorResult] = useState<{
|
|
129
|
+
requestId: string
|
|
130
|
+
ok: boolean
|
|
131
|
+
error?: string
|
|
132
|
+
} | null>(null)
|
|
133
|
+
const [editorValidation, setEditorValidation] = useState<{
|
|
134
|
+
requestId: string
|
|
135
|
+
valid: boolean
|
|
136
|
+
errors: string[]
|
|
137
|
+
} | null>(null)
|
|
138
|
+
const [editorSourceValidation, setEditorSourceValidation] = useState<{
|
|
139
|
+
requestId: string
|
|
140
|
+
valid: boolean
|
|
141
|
+
errors: string[]
|
|
142
|
+
} | null>(null)
|
|
143
|
+
const [deviceModel, setDeviceModel] = useState<DeviceModelSpec>(() =>
|
|
144
|
+
initialDeviceModel !== undefined && isKnownDeviceModel(initialDeviceModel)
|
|
145
|
+
? getDeviceModel(initialDeviceModel)
|
|
146
|
+
: DEFAULT_DEVICE_MODEL,
|
|
147
|
+
)
|
|
148
|
+
const [isFullscreen, setIsFullscreen] = useState(false)
|
|
149
|
+
const clientRef = useRef<WsClient | null>(null)
|
|
150
|
+
const iframeRef = useRef<HTMLIFrameElement | null>(null)
|
|
151
|
+
const deckContainerRef = useRef<HTMLDivElement | null>(null)
|
|
152
|
+
// ponytail: ignore the first `closed` after an `open` — happens during
|
|
153
|
+
// WS-replacement that some React navigations trigger. Latch only after a
|
|
154
|
+
// short delay so transient reconnects don't pop the banner.
|
|
155
|
+
const lastStatusRef = useRef<WsStatus | null>(null)
|
|
156
|
+
const reconnectLatchTimerRef = useRef<number | null>(null)
|
|
157
|
+
const disconnectedSinceRef = useRef<number | null>(null)
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
clientRef.current = createWsClient({
|
|
161
|
+
url: wsUrl,
|
|
162
|
+
...(token !== "" ? { token } : {}),
|
|
163
|
+
onOpen: () => {
|
|
164
|
+
clientRef.current?.send(
|
|
165
|
+
JSON.stringify({ type: "editor-state-request" }),
|
|
166
|
+
)
|
|
167
|
+
},
|
|
168
|
+
onStatus: (status) => {
|
|
169
|
+
const previous = lastStatusRef.current
|
|
170
|
+
lastStatusRef.current = status
|
|
171
|
+
setConnectionStatus(status)
|
|
172
|
+
setAttempt(clientRef.current?.attemptCount() ?? 0)
|
|
173
|
+
if (status === "authorization-failed") return
|
|
174
|
+
if (status === "open") {
|
|
175
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
176
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
177
|
+
reconnectLatchTimerRef.current = null
|
|
178
|
+
}
|
|
179
|
+
setDisconnectedSince(null)
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
if (status === "connecting") {
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (status === "closed") {
|
|
186
|
+
if (previous === "open") {
|
|
187
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
188
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
189
|
+
}
|
|
190
|
+
const openedAt = Date.now()
|
|
191
|
+
reconnectLatchTimerRef.current = window.setTimeout(() => {
|
|
192
|
+
reconnectLatchTimerRef.current = null
|
|
193
|
+
setDisconnectedSince((current) =>
|
|
194
|
+
current === null ? openedAt : current,
|
|
195
|
+
)
|
|
196
|
+
}, 500)
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
setDisconnectedSince((current) =>
|
|
200
|
+
current === null ? Date.now() : current,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
wsFactory: (url: string) => {
|
|
205
|
+
const ws = new WebSocket(url)
|
|
206
|
+
return ws as unknown as {
|
|
207
|
+
send: (d: string) => void
|
|
208
|
+
close: () => void
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
onMessage: (raw: unknown) => {
|
|
212
|
+
let m: Record<string, unknown>
|
|
213
|
+
try {
|
|
214
|
+
m = JSON.parse(String(raw)) as Record<string, unknown>
|
|
215
|
+
} catch {
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
if (m.type === "device-info") {
|
|
219
|
+
const device = m.device as Record<string, unknown> | undefined
|
|
220
|
+
const modelId = device?.model
|
|
221
|
+
if (typeof modelId === "string" && isKnownDeviceModel(modelId)) {
|
|
222
|
+
setDeviceModel(getDeviceModel(modelId))
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (m.type === "deck-config") {
|
|
226
|
+
const id = typeof m.deckId === "string" ? m.deckId : ""
|
|
227
|
+
setDeckId(id)
|
|
228
|
+
}
|
|
229
|
+
if (m.type === "addons-inventory") {
|
|
230
|
+
const addons = m.addons
|
|
231
|
+
if (Array.isArray(addons)) {
|
|
232
|
+
setAddonInventory({ addons } as AddonInventory)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (m.type === "deck-tree") {
|
|
236
|
+
if (typeof m.rootId === "string" && Array.isArray(m.decks)) {
|
|
237
|
+
setDeckTree({ rootId: m.rootId, decks: m.decks })
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (
|
|
241
|
+
m.type === "editor-state" &&
|
|
242
|
+
typeof m.revision === "number" &&
|
|
243
|
+
Array.isArray(m.sources)
|
|
244
|
+
) {
|
|
245
|
+
setEditorState({
|
|
246
|
+
revision: m.revision,
|
|
247
|
+
config: m.config,
|
|
248
|
+
sources: m.sources.filter(
|
|
249
|
+
(source): source is string => typeof source === "string",
|
|
250
|
+
),
|
|
251
|
+
sourceContents:
|
|
252
|
+
m.sourceContents !== null && typeof m.sourceContents === "object"
|
|
253
|
+
? Object.fromEntries(
|
|
254
|
+
Object.entries(m.sourceContents).filter(
|
|
255
|
+
(entry): entry is [string, string] =>
|
|
256
|
+
typeof entry[0] === "string" &&
|
|
257
|
+
typeof entry[1] === "string",
|
|
258
|
+
),
|
|
259
|
+
)
|
|
260
|
+
: {},
|
|
261
|
+
themes: Array.isArray(m.themes)
|
|
262
|
+
? m.themes.filter(
|
|
263
|
+
(theme): theme is { name: string; active?: boolean } =>
|
|
264
|
+
typeof theme?.name === "string",
|
|
265
|
+
)
|
|
266
|
+
: [],
|
|
267
|
+
themeVariants:
|
|
268
|
+
m.themeVariants !== null && typeof m.themeVariants === "object"
|
|
269
|
+
? (m.themeVariants as EditorState["themeVariants"])
|
|
270
|
+
: {},
|
|
271
|
+
surfaces: Array.isArray(m.surfaces)
|
|
272
|
+
? (m.surfaces as EditorState["surfaces"])
|
|
273
|
+
: [],
|
|
274
|
+
buttonSchemas:
|
|
275
|
+
m.buttonSchemas !== null && typeof m.buttonSchemas === "object"
|
|
276
|
+
? (m.buttonSchemas as Record<string, Record<string, unknown>>)
|
|
277
|
+
: {},
|
|
278
|
+
canUndo: m.canUndo === true,
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
if (
|
|
282
|
+
m.type === "editor-mutation-result" &&
|
|
283
|
+
typeof m.requestId === "string"
|
|
284
|
+
) {
|
|
285
|
+
setEditorResult({
|
|
286
|
+
requestId: m.requestId,
|
|
287
|
+
ok: m.ok === true,
|
|
288
|
+
...(typeof m.error === "string" ? { error: m.error } : {}),
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
if (
|
|
292
|
+
m.type === "editor-validation-result" &&
|
|
293
|
+
typeof m.requestId === "string"
|
|
294
|
+
) {
|
|
295
|
+
setEditorValidation({
|
|
296
|
+
requestId: m.requestId,
|
|
297
|
+
valid: m.valid === true,
|
|
298
|
+
errors: Array.isArray(m.errors)
|
|
299
|
+
? m.errors.filter(
|
|
300
|
+
(error): error is string => typeof error === "string",
|
|
301
|
+
)
|
|
302
|
+
: [],
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
if (
|
|
306
|
+
m.type === "editor-source-validation-result" &&
|
|
307
|
+
typeof m.requestId === "string"
|
|
308
|
+
) {
|
|
309
|
+
setEditorSourceValidation({
|
|
310
|
+
requestId: m.requestId,
|
|
311
|
+
valid: m.valid === true,
|
|
312
|
+
errors: Array.isArray(m.errors)
|
|
313
|
+
? m.errors.filter(
|
|
314
|
+
(error): error is string => typeof error === "string",
|
|
315
|
+
)
|
|
316
|
+
: [],
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
if (typeof m.type === "string" && m.type.endsWith("error")) {
|
|
320
|
+
setLastError(String(m.type))
|
|
321
|
+
}
|
|
322
|
+
if (m.type === "iframe-reload") {
|
|
323
|
+
// ponytail: asked by the CLI to reload the frontend iframe. The
|
|
324
|
+
// SPA stays mounted (so device/connection state survives) — only
|
|
325
|
+
// the inner iframe is reloaded, picking up the latest frontend
|
|
326
|
+
// bundle from vite (which has HMR'd the source).
|
|
327
|
+
iframeRef.current?.contentWindow?.location.reload()
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
})
|
|
331
|
+
return () => {
|
|
332
|
+
clientRef.current?.close()
|
|
333
|
+
clientRef.current = null
|
|
334
|
+
if (reconnectLatchTimerRef.current !== null) {
|
|
335
|
+
window.clearTimeout(reconnectLatchTimerRef.current)
|
|
336
|
+
reconnectLatchTimerRef.current = null
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}, [wsUrl])
|
|
340
|
+
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
if (disconnectedSince === null) return
|
|
343
|
+
const timer = setInterval(() => setNow(Date.now()), 250)
|
|
344
|
+
return () => clearInterval(timer)
|
|
345
|
+
}, [disconnectedSince])
|
|
346
|
+
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
const computeDeckScale = () => {
|
|
349
|
+
const el = deckContainerRef.current
|
|
350
|
+
if (el === null || typeof window === "undefined") return
|
|
351
|
+
// Measure the padded content box. In deck-only mode this also respects
|
|
352
|
+
// the safe-area space reserved for the fullscreen control.
|
|
353
|
+
const style = window.getComputedStyle(el)
|
|
354
|
+
const px = (value: string): number => Number.parseFloat(value) || 0
|
|
355
|
+
const containerW =
|
|
356
|
+
el.clientWidth - px(style.paddingLeft) - px(style.paddingRight)
|
|
357
|
+
const containerH =
|
|
358
|
+
el.clientHeight - px(style.paddingTop) - px(style.paddingBottom)
|
|
359
|
+
if (containerW <= 0 || containerH <= 0) return
|
|
360
|
+
const rows = Math.ceil(deviceModel.keyCount / deviceModel.columns)
|
|
361
|
+
const { width, height } = deckDimensions(
|
|
362
|
+
{ columns: deviceModel.columns, rows },
|
|
363
|
+
DECK_GAP_PX,
|
|
364
|
+
)
|
|
365
|
+
setDeckScale(Math.min(containerW / width, containerH / height, 1))
|
|
366
|
+
}
|
|
367
|
+
computeDeckScale()
|
|
368
|
+
const ro =
|
|
369
|
+
typeof ResizeObserver !== "undefined"
|
|
370
|
+
? new ResizeObserver(() => computeDeckScale())
|
|
371
|
+
: null
|
|
372
|
+
if (ro !== null && deckContainerRef.current !== null) {
|
|
373
|
+
ro.observe(deckContainerRef.current)
|
|
374
|
+
}
|
|
375
|
+
window.addEventListener("resize", computeDeckScale)
|
|
376
|
+
return () => {
|
|
377
|
+
ro?.disconnect()
|
|
378
|
+
window.removeEventListener("resize", computeDeckScale)
|
|
379
|
+
}
|
|
380
|
+
}, [deviceModel])
|
|
381
|
+
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
if (typeof window === "undefined") return
|
|
384
|
+
const hash = window.location.hash.replace(/^#\/?/, "")
|
|
385
|
+
if (isValidSection(hash)) {
|
|
386
|
+
setActiveSection(hash)
|
|
387
|
+
}
|
|
388
|
+
}, [])
|
|
389
|
+
|
|
390
|
+
useEffect(() => {
|
|
391
|
+
const handleFullscreenChange = (): void => {
|
|
392
|
+
setIsFullscreen(document.fullscreenElement !== null)
|
|
393
|
+
}
|
|
394
|
+
document.addEventListener("fullscreenchange", handleFullscreenChange)
|
|
395
|
+
return () =>
|
|
396
|
+
document.removeEventListener("fullscreenchange", handleFullscreenChange)
|
|
397
|
+
}, [])
|
|
398
|
+
|
|
399
|
+
const onSelect = (path: string): void => {
|
|
400
|
+
if (!isValidSection(path)) return
|
|
401
|
+
if (path === "config") setConfigView("editor")
|
|
402
|
+
setActiveSection(path)
|
|
403
|
+
if (typeof window !== "undefined") {
|
|
404
|
+
window.location.hash = `#/${path}`
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const renderActive = (): React.ReactNode => {
|
|
409
|
+
if (activeSection === "bridge-logs") return <BridgeLogsPage />
|
|
410
|
+
if (activeSection === "service-logs") return <ServiceLogsPage />
|
|
411
|
+
if (activeSection === "addons")
|
|
412
|
+
return <AddonsPage addonInventory={addonInventory} />
|
|
413
|
+
if (activeSection === "decks") return <DecksPage deckTree={deckTree} />
|
|
414
|
+
if (activeSection === "config")
|
|
415
|
+
return (
|
|
416
|
+
<ConfigPage
|
|
417
|
+
wsClient={clientRef.current}
|
|
418
|
+
editorState={editorState}
|
|
419
|
+
sourceValidation={editorSourceValidation}
|
|
420
|
+
mutationResult={editorResult}
|
|
421
|
+
activeTab={configView}
|
|
422
|
+
onTabChange={setConfigView}
|
|
423
|
+
revision={editorState?.revision ?? null}
|
|
424
|
+
canUndo={editorState?.canUndo ?? false}
|
|
425
|
+
onUndo={() => {
|
|
426
|
+
if (editorState === null) return
|
|
427
|
+
clientRef.current?.send(
|
|
428
|
+
JSON.stringify({
|
|
429
|
+
type: "editor-undo",
|
|
430
|
+
requestId: `editor-undo-${Date.now()}`,
|
|
431
|
+
revision: editorState.revision,
|
|
432
|
+
}),
|
|
433
|
+
)
|
|
434
|
+
}}
|
|
435
|
+
editor={
|
|
436
|
+
<EditorPage
|
|
437
|
+
wsClient={clientRef.current}
|
|
438
|
+
state={editorState}
|
|
439
|
+
result={editorResult}
|
|
440
|
+
validation={editorValidation}
|
|
441
|
+
addonInventory={addonInventory}
|
|
442
|
+
frontendUrl={ENV_FRONTEND_URL}
|
|
443
|
+
device={deviceModel}
|
|
444
|
+
token={token}
|
|
445
|
+
onGesture={sendButtonAction}
|
|
446
|
+
runtimeDeckId={deckId || null}
|
|
447
|
+
onDeckSelect={(selectedDeckId) =>
|
|
448
|
+
clientRef.current?.send(
|
|
449
|
+
JSON.stringify({
|
|
450
|
+
type: "select-deck",
|
|
451
|
+
deckId: selectedDeckId,
|
|
452
|
+
}),
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
/>
|
|
456
|
+
}
|
|
457
|
+
/>
|
|
458
|
+
)
|
|
459
|
+
if (activeSection === "about") return <AboutPage />
|
|
460
|
+
return null
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const sendButtonAction = (msg: {
|
|
464
|
+
deckId: string
|
|
465
|
+
position: number
|
|
466
|
+
gesture: "tap" | "dbl-tap" | "hold"
|
|
467
|
+
}): void => {
|
|
468
|
+
clientRef.current?.send(JSON.stringify(msg))
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const setDevice = (deviceId: string): void => {
|
|
472
|
+
if (
|
|
473
|
+
!VIRTUAL_DEVICE_IDS.includes(
|
|
474
|
+
deviceId as (typeof VIRTUAL_DEVICE_IDS)[number],
|
|
475
|
+
)
|
|
476
|
+
)
|
|
477
|
+
return
|
|
478
|
+
setDeviceModel(getDeviceModel(deviceId))
|
|
479
|
+
clientRef.current?.send(JSON.stringify({ type: "set-device", deviceId }))
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const enterFullscreen = (): void => {
|
|
483
|
+
if (typeof document === "undefined") return
|
|
484
|
+
if (document.fullscreenElement == null) {
|
|
485
|
+
void document.documentElement.requestFullscreen()
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const elapsed = disconnectedSince === null ? 0 : now - disconnectedSince
|
|
490
|
+
const showBsod =
|
|
491
|
+
connectionStatus !== "open" &&
|
|
492
|
+
disconnectedSince !== null &&
|
|
493
|
+
elapsed >= 30000
|
|
494
|
+
const showBanner =
|
|
495
|
+
connectionStatus !== "open" && disconnectedSince !== null && elapsed < 30000
|
|
496
|
+
|
|
497
|
+
if (connectionStatus === "authorization-failed") {
|
|
498
|
+
return (
|
|
499
|
+
<div
|
|
500
|
+
data-testid="authorization-failed"
|
|
501
|
+
className="flex min-h-screen items-center justify-center bg-neutral-950 p-6 text-center text-sm text-neutral-200"
|
|
502
|
+
>
|
|
503
|
+
<p className="max-w-md">
|
|
504
|
+
Authorization token changed. Close this window and run{" "}
|
|
505
|
+
<code className="font-mono text-sky-300">sirenodeck config-ui</code>{" "}
|
|
506
|
+
to get access again
|
|
507
|
+
</p>
|
|
508
|
+
</div>
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return (
|
|
513
|
+
<Shell
|
|
514
|
+
activeSection={activeSection}
|
|
515
|
+
onSelect={onSelect}
|
|
516
|
+
hideSidebar={deckOnly}
|
|
517
|
+
pageTitle={
|
|
518
|
+
activeSection === "config"
|
|
519
|
+
? configView === "editor"
|
|
520
|
+
? "Visual editor"
|
|
521
|
+
: "Config"
|
|
522
|
+
: activeSection.replaceAll("-", " ")
|
|
523
|
+
}
|
|
524
|
+
wsUrl={wsUrl}
|
|
525
|
+
frontendUrl={ENV_FRONTEND_URL}
|
|
526
|
+
connectionStatus={connectionStatus}
|
|
527
|
+
emulatorMode={ENV_EMULATOR_MODE}
|
|
528
|
+
devMode={ENV_DEV_MODE}
|
|
529
|
+
deviceSelector={
|
|
530
|
+
ENV_EMULATOR_MODE || ENV_REMOTE_MODE ? (
|
|
531
|
+
<DeviceSelector device={deviceModel.id} onChange={setDevice} />
|
|
532
|
+
) : undefined
|
|
533
|
+
}
|
|
534
|
+
content={
|
|
535
|
+
<>
|
|
536
|
+
<Toast.Provider placement="bottom end" />
|
|
537
|
+
{deckOnly ? (
|
|
538
|
+
<div
|
|
539
|
+
ref={deckContainerRef}
|
|
540
|
+
data-testid="deck-only-view"
|
|
541
|
+
className="flex h-full w-full items-center justify-center overflow-hidden"
|
|
542
|
+
>
|
|
543
|
+
{deckId === "" ? (
|
|
544
|
+
<p className="font-mono text-xs uppercase tracking-widest text-neutral-500">
|
|
545
|
+
Awaiting deck-config…
|
|
546
|
+
</p>
|
|
547
|
+
) : (
|
|
548
|
+
// ponytail: keep the fixed-size deck from flex-shrinking
|
|
549
|
+
// before applying the scale calculated for the mobile viewport.
|
|
550
|
+
<div
|
|
551
|
+
className="shrink-0"
|
|
552
|
+
style={{
|
|
553
|
+
transform: `scale(${deckScale})`,
|
|
554
|
+
transformOrigin: "center",
|
|
555
|
+
}}
|
|
556
|
+
>
|
|
557
|
+
<DeckFrame
|
|
558
|
+
frontendUrl={ENV_FRONTEND_URL}
|
|
559
|
+
device={deviceModel}
|
|
560
|
+
deckId={deckId}
|
|
561
|
+
token={token}
|
|
562
|
+
onGesture={sendButtonAction}
|
|
563
|
+
onIframeRef={(el) => {
|
|
564
|
+
iframeRef.current = el
|
|
565
|
+
}}
|
|
566
|
+
bare
|
|
567
|
+
/>
|
|
568
|
+
</div>
|
|
569
|
+
)}
|
|
570
|
+
</div>
|
|
571
|
+
) : (
|
|
572
|
+
<div className="flex h-full flex-col">
|
|
573
|
+
<div className="flex flex-1 overflow-hidden">
|
|
574
|
+
<section className="flex-1 overflow-auto p-4">
|
|
575
|
+
{activeSection === "device" ? (
|
|
576
|
+
deckId === "" ? (
|
|
577
|
+
<p className="font-mono text-xs uppercase tracking-widest text-neutral-500">
|
|
578
|
+
Awaiting deck-config…
|
|
579
|
+
</p>
|
|
580
|
+
) : (
|
|
581
|
+
<DeckFrame
|
|
582
|
+
frontendUrl={ENV_FRONTEND_URL}
|
|
583
|
+
device={deviceModel}
|
|
584
|
+
deckId={deckId}
|
|
585
|
+
token={token}
|
|
586
|
+
onGesture={sendButtonAction}
|
|
587
|
+
onIframeRef={(el) => {
|
|
588
|
+
iframeRef.current = el
|
|
589
|
+
}}
|
|
590
|
+
/>
|
|
591
|
+
)
|
|
592
|
+
) : (
|
|
593
|
+
renderActive()
|
|
594
|
+
)}
|
|
595
|
+
</section>
|
|
596
|
+
</div>
|
|
597
|
+
</div>
|
|
598
|
+
)}
|
|
599
|
+
{showBanner && (
|
|
600
|
+
<div
|
|
601
|
+
data-testid="reconnecting-banner"
|
|
602
|
+
className="fixed top-2 left-1/2 z-50 -translate-x-1/2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-4 py-2 text-center text-amber-200 backdrop-blur"
|
|
603
|
+
>
|
|
604
|
+
<span className="font-medium">Reconnecting…</span>
|
|
605
|
+
<span className="ml-2 text-amber-300/80">
|
|
606
|
+
attempt {attempt} · {Math.floor(elapsed / 1000)}s elapsed
|
|
607
|
+
</span>
|
|
608
|
+
</div>
|
|
609
|
+
)}
|
|
610
|
+
{showBsod && (
|
|
611
|
+
<div
|
|
612
|
+
data-testid="disconnected-overlay"
|
|
613
|
+
className="fixed inset-0 z-50 flex items-center justify-center bg-neutral-950/90 backdrop-blur"
|
|
614
|
+
>
|
|
615
|
+
<div className="w-full max-w-md rounded-xl border border-red-500/40 bg-neutral-900/95 p-8 text-center shadow-2xl">
|
|
616
|
+
<h2 className="mb-2 text-2xl font-semibold text-red-400">
|
|
617
|
+
Connection lost
|
|
618
|
+
</h2>
|
|
619
|
+
<p className="mb-6 text-sm text-neutral-400">
|
|
620
|
+
{connectionStatus === "failed"
|
|
621
|
+
? `Failed to reconnect after ${attempt} attempts`
|
|
622
|
+
: "Disconnected"}
|
|
623
|
+
</p>
|
|
624
|
+
<dl className="space-y-2 text-left text-sm">
|
|
625
|
+
<div className="flex justify-between">
|
|
626
|
+
<dt className="text-neutral-500">Status</dt>
|
|
627
|
+
<dd className="font-mono text-neutral-200">
|
|
628
|
+
{connectionStatus}
|
|
629
|
+
</dd>
|
|
630
|
+
</div>
|
|
631
|
+
<div className="flex justify-between">
|
|
632
|
+
<dt className="text-neutral-500">Reconnect attempts</dt>
|
|
633
|
+
<dd className="font-mono text-neutral-200">{attempt}</dd>
|
|
634
|
+
</div>
|
|
635
|
+
{lastError !== null && (
|
|
636
|
+
<div className="flex justify-between">
|
|
637
|
+
<dt className="text-neutral-500">Last error</dt>
|
|
638
|
+
<dd className="truncate font-mono text-neutral-200">
|
|
639
|
+
{lastError}
|
|
640
|
+
</dd>
|
|
641
|
+
</div>
|
|
642
|
+
)}
|
|
643
|
+
<div className="flex justify-between">
|
|
644
|
+
<dt className="text-neutral-500">Elapsed</dt>
|
|
645
|
+
<dd className="font-mono text-neutral-200">
|
|
646
|
+
{Math.floor(elapsed / 60 / 1000)
|
|
647
|
+
.toString()
|
|
648
|
+
.padStart(2, "0")}
|
|
649
|
+
:
|
|
650
|
+
{Math.floor((elapsed / 1000) % 60)
|
|
651
|
+
.toString()
|
|
652
|
+
.padStart(2, "0")}
|
|
653
|
+
</dd>
|
|
654
|
+
</div>
|
|
655
|
+
</dl>
|
|
656
|
+
</div>
|
|
657
|
+
</div>
|
|
658
|
+
)}
|
|
659
|
+
{deckOnly && !isFullscreen && (
|
|
660
|
+
<button
|
|
661
|
+
type="button"
|
|
662
|
+
onClick={enterFullscreen}
|
|
663
|
+
aria-label="Enter fullscreen"
|
|
664
|
+
data-testid="fullscreen-toggle"
|
|
665
|
+
className="fixed top-[calc(env(safe-area-inset-top)+0.75rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex h-12 w-12 items-center justify-center rounded-full border border-white/10 bg-neutral-800/80 text-[10px] font-medium uppercase tracking-wide text-neutral-100 shadow-lg backdrop-blur hover:bg-neutral-700/80"
|
|
666
|
+
>
|
|
667
|
+
Full
|
|
668
|
+
</button>
|
|
669
|
+
)}
|
|
670
|
+
</>
|
|
671
|
+
}
|
|
672
|
+
wsClient={clientRef.current}
|
|
673
|
+
/>
|
|
674
|
+
)
|
|
675
|
+
}
|