@sirenodeck/sirenodeck 0.2.7 → 0.2.10
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 +327 -41554
- 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/coding-agents/global/backend.ts +15 -1
- package/src/builtin-addons/internal-settings/index.ts +0 -1
- package/src/builtin-addons/internal-settings/logo72x72.png +0 -0
- package/src/builtin-addons/media/backend.ts +21 -0
- package/src/builtin-addons/system-status/README.md +1 -1
- package/src/builtin-addons/system-status/domain/display-metrics.ts +1 -1
- package/src/builtin-addons/system-status/manifest.ts +1 -1
- package/src/cli/commands/emulator-mode.ts +27 -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,186 @@
|
|
|
1
|
+
import { ChannelRegistry } from "sirenodeck/react"
|
|
2
|
+
import {
|
|
3
|
+
helloMessageSchema,
|
|
4
|
+
wsMessageSchema,
|
|
5
|
+
type WsMessage,
|
|
6
|
+
} from "@/api/protocol"
|
|
7
|
+
|
|
8
|
+
export type ConnectionStatus =
|
|
9
|
+
| "connecting"
|
|
10
|
+
| "open"
|
|
11
|
+
| "closed"
|
|
12
|
+
| "failed"
|
|
13
|
+
| "authorization-failed"
|
|
14
|
+
|
|
15
|
+
export interface WsClientOptions {
|
|
16
|
+
url: string
|
|
17
|
+
token?: string
|
|
18
|
+
protocolVersion?: number
|
|
19
|
+
onMessage?: (message: WsMessage) => void
|
|
20
|
+
onStatus?: (status: ConnectionStatus) => void
|
|
21
|
+
backoffMs?: ReadonlyArray<number>
|
|
22
|
+
maxAttempts?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DEFAULT_BACKOFF = [1000, 2000, 4000, 8000, 16000, 30000]
|
|
26
|
+
const DEFAULT_MAX_ATTEMPTS = 10
|
|
27
|
+
|
|
28
|
+
export interface WsClient {
|
|
29
|
+
connect(): void
|
|
30
|
+
close(): void
|
|
31
|
+
send(message: WsMessage): void
|
|
32
|
+
subscribeChannels(channels: string[]): void
|
|
33
|
+
getAttempt(): number
|
|
34
|
+
getLastError(): string | null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const createWsClient = (options: WsClientOptions): WsClient => {
|
|
38
|
+
const {
|
|
39
|
+
url,
|
|
40
|
+
token,
|
|
41
|
+
protocolVersion = 1,
|
|
42
|
+
onMessage,
|
|
43
|
+
onStatus,
|
|
44
|
+
backoffMs = DEFAULT_BACKOFF,
|
|
45
|
+
maxAttempts = DEFAULT_MAX_ATTEMPTS,
|
|
46
|
+
} = options
|
|
47
|
+
|
|
48
|
+
let socket: WebSocket | null = null
|
|
49
|
+
let attempt = 0
|
|
50
|
+
let manuallyClosed = false
|
|
51
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
52
|
+
let connected = false
|
|
53
|
+
let lastError: string | null = null
|
|
54
|
+
const pendingMessages: WsMessage[] = []
|
|
55
|
+
const subscribedChannels = new Set<string>()
|
|
56
|
+
|
|
57
|
+
const setStatus = (status: ConnectionStatus): void => onStatus?.(status)
|
|
58
|
+
|
|
59
|
+
const flushPending = (): void => {
|
|
60
|
+
while (
|
|
61
|
+
pendingMessages.length > 0 &&
|
|
62
|
+
socket?.readyState === WebSocket.OPEN
|
|
63
|
+
) {
|
|
64
|
+
const msg = pendingMessages.shift()!
|
|
65
|
+
socket.send(JSON.stringify(msg))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const scheduleReconnect = (): void => {
|
|
70
|
+
if (manuallyClosed) return
|
|
71
|
+
if (attempt >= maxAttempts) {
|
|
72
|
+
setStatus("failed")
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const delay = backoffMs[Math.min(attempt, backoffMs.length - 1)] ?? 30000
|
|
76
|
+
attempt += 1
|
|
77
|
+
timer = setTimeout(connect, delay)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const connect = (): void => {
|
|
81
|
+
if (manuallyClosed) return
|
|
82
|
+
setStatus("connecting")
|
|
83
|
+
socket = new WebSocket(url)
|
|
84
|
+
socket.addEventListener("open", () => {
|
|
85
|
+
attempt = 0
|
|
86
|
+
connected = true
|
|
87
|
+
setStatus("open")
|
|
88
|
+
const hello = helloMessageSchema.parse({
|
|
89
|
+
type: "hello",
|
|
90
|
+
version: protocolVersion,
|
|
91
|
+
...(token !== undefined ? { token } : {}),
|
|
92
|
+
})
|
|
93
|
+
socket?.send(JSON.stringify(hello))
|
|
94
|
+
flushPending()
|
|
95
|
+
if (subscribedChannels.size > 0) {
|
|
96
|
+
const msg: WsMessage = {
|
|
97
|
+
type: "subscribe-channels",
|
|
98
|
+
channels: [...subscribedChannels],
|
|
99
|
+
}
|
|
100
|
+
socket?.send(JSON.stringify(msg))
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
socket.addEventListener("message", (event: MessageEvent) => {
|
|
104
|
+
try {
|
|
105
|
+
const parsed = wsMessageSchema.safeParse(JSON.parse(String(event.data)))
|
|
106
|
+
if (parsed.success) {
|
|
107
|
+
onMessage?.(parsed.data)
|
|
108
|
+
if (parsed.data.type === "state") {
|
|
109
|
+
for (const [channel, payload] of Object.entries(
|
|
110
|
+
parsed.data.channels,
|
|
111
|
+
)) {
|
|
112
|
+
ChannelRegistry.instance().publish(channel, payload)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
// ignore invalid frames
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
socket.addEventListener("close", (event: CloseEvent) => {
|
|
121
|
+
connected = false
|
|
122
|
+
if (event.code === 4001) {
|
|
123
|
+
lastError =
|
|
124
|
+
"Token mismatch — check that SIRENO_TOKEN matches the daemon"
|
|
125
|
+
setStatus("authorization-failed")
|
|
126
|
+
return
|
|
127
|
+
} else if (event.code !== 1000 && event.code !== 0) {
|
|
128
|
+
lastError =
|
|
129
|
+
event.reason?.length > 0
|
|
130
|
+
? event.reason
|
|
131
|
+
: `WS closed with code ${event.code}`
|
|
132
|
+
}
|
|
133
|
+
setStatus("closed")
|
|
134
|
+
scheduleReconnect()
|
|
135
|
+
})
|
|
136
|
+
socket.addEventListener("error", () => {
|
|
137
|
+
lastError = "WebSocket connection error"
|
|
138
|
+
socket?.close()
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const close = (): void => {
|
|
143
|
+
manuallyClosed = true
|
|
144
|
+
connected = false
|
|
145
|
+
pendingMessages.length = 0
|
|
146
|
+
subscribedChannels.clear()
|
|
147
|
+
if (timer !== null) clearTimeout(timer)
|
|
148
|
+
if (socket === null) return
|
|
149
|
+
if (
|
|
150
|
+
socket.readyState === WebSocket.CONNECTING ||
|
|
151
|
+
socket.readyState === WebSocket.OPEN
|
|
152
|
+
) {
|
|
153
|
+
socket.close()
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const send = (message: WsMessage): void => {
|
|
158
|
+
if (socket?.readyState === WebSocket.OPEN) {
|
|
159
|
+
socket.send(JSON.stringify(message))
|
|
160
|
+
} else {
|
|
161
|
+
pendingMessages.push(message)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const subscribeChannels = (channels: string[]): void => {
|
|
166
|
+
const newChannels = channels.filter((ch) => !subscribedChannels.has(ch))
|
|
167
|
+
if (newChannels.length === 0) return
|
|
168
|
+
for (const ch of newChannels) subscribedChannels.add(ch)
|
|
169
|
+
if (socket?.readyState === WebSocket.OPEN) {
|
|
170
|
+
const msg: WsMessage = {
|
|
171
|
+
type: "subscribe-channels",
|
|
172
|
+
channels: newChannels,
|
|
173
|
+
}
|
|
174
|
+
socket.send(JSON.stringify(msg))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
connect,
|
|
180
|
+
close,
|
|
181
|
+
send,
|
|
182
|
+
subscribeChannels,
|
|
183
|
+
getAttempt: () => attempt,
|
|
184
|
+
getLastError: () => lastError,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback } from "react"
|
|
2
|
+
|
|
3
|
+
import type { ButtonActionMessage } from "@/api/protocol-internal"
|
|
4
|
+
|
|
5
|
+
import { useWebSocketSend } from "./ws-context"
|
|
6
|
+
|
|
7
|
+
export interface UseButtonActionReturn {
|
|
8
|
+
readonly fire: (gesture?: ButtonActionMessage["gesture"]) => void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const useButtonAction = (
|
|
12
|
+
deckId: string,
|
|
13
|
+
position: number,
|
|
14
|
+
): UseButtonActionReturn => {
|
|
15
|
+
const send = useWebSocketSend()
|
|
16
|
+
|
|
17
|
+
const fire = useCallback(
|
|
18
|
+
(gesture: ButtonActionMessage["gesture"] = "tap") => {
|
|
19
|
+
if (send === null) return
|
|
20
|
+
send({
|
|
21
|
+
type: "button-action",
|
|
22
|
+
deckId,
|
|
23
|
+
position,
|
|
24
|
+
gesture,
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
[send, deckId, position],
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return { fire }
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from "react"
|
|
2
|
+
|
|
3
|
+
import type { WsMessage } from "@/api/protocol-internal"
|
|
4
|
+
|
|
5
|
+
export type WebSocketSend = (message: WsMessage) => void
|
|
6
|
+
|
|
7
|
+
const WebSocketContext = createContext<WebSocketSend | null>(null)
|
|
8
|
+
|
|
9
|
+
export interface WebSocketProviderProps {
|
|
10
|
+
readonly value: WebSocketSend | null
|
|
11
|
+
readonly children: ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const WebSocketProvider = ({
|
|
15
|
+
value,
|
|
16
|
+
children,
|
|
17
|
+
}: WebSocketProviderProps) => (
|
|
18
|
+
<WebSocketContext.Provider value={value}>
|
|
19
|
+
{children}
|
|
20
|
+
</WebSocketContext.Provider>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export const useWebSocketSend = (): WebSocketSend | null =>
|
|
24
|
+
useContext(WebSocketContext)
|