@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,115 @@
|
|
|
1
|
+
export type ServiceLogLevel =
|
|
2
|
+
| "trace"
|
|
3
|
+
| "debug"
|
|
4
|
+
| "info"
|
|
5
|
+
| "warn"
|
|
6
|
+
| "error"
|
|
7
|
+
| "fatal"
|
|
8
|
+
|
|
9
|
+
export interface ServiceLogEntry {
|
|
10
|
+
readonly ts: number
|
|
11
|
+
readonly level: ServiceLogLevel
|
|
12
|
+
readonly msg: string
|
|
13
|
+
readonly component?: string
|
|
14
|
+
readonly deckId?: string
|
|
15
|
+
readonly position?: number
|
|
16
|
+
readonly addonName?: string
|
|
17
|
+
readonly gesture?: "tap" | "dbl-tap" | "hold"
|
|
18
|
+
readonly keyIndex?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BridgeMessageEntry {
|
|
22
|
+
readonly ts: number
|
|
23
|
+
readonly direction: "sent" | "received"
|
|
24
|
+
readonly type: string
|
|
25
|
+
readonly channel: string | null
|
|
26
|
+
readonly payload: unknown
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ServiceLogFilter {
|
|
30
|
+
readonly level?: ServiceLogLevel
|
|
31
|
+
readonly sinceMs?: number
|
|
32
|
+
readonly contentSubstring?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface BridgeMessageFilter {
|
|
36
|
+
readonly direction?: "all" | "sent" | "received"
|
|
37
|
+
readonly channel?: string
|
|
38
|
+
readonly type?: string
|
|
39
|
+
readonly contentSubstring?: string
|
|
40
|
+
readonly sinceMs?: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const SERVICE_LOG_CAP = 1000
|
|
44
|
+
const BRIDGE_MSG_CAP = 1000
|
|
45
|
+
|
|
46
|
+
const serviceLogs: ServiceLogEntry[] = []
|
|
47
|
+
const bridgeMessages: BridgeMessageEntry[] = []
|
|
48
|
+
|
|
49
|
+
export const appendServiceLog = (entry: ServiceLogEntry): void => {
|
|
50
|
+
serviceLogs.push(entry)
|
|
51
|
+
if (serviceLogs.length > SERVICE_LOG_CAP) {
|
|
52
|
+
serviceLogs.shift()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const getServiceLogs = (
|
|
57
|
+
filter: ServiceLogFilter = {},
|
|
58
|
+
): ServiceLogEntry[] => {
|
|
59
|
+
return serviceLogs.filter((entry) => {
|
|
60
|
+
if (filter.level !== undefined && entry.level !== filter.level) return false
|
|
61
|
+
if (filter.sinceMs !== undefined && entry.ts < filter.sinceMs) return false
|
|
62
|
+
if (
|
|
63
|
+
filter.contentSubstring !== undefined &&
|
|
64
|
+
!entry.msg.includes(filter.contentSubstring)
|
|
65
|
+
) {
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
return true
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const clearServiceLogs = (): void => {
|
|
73
|
+
serviceLogs.length = 0
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const appendBridgeMessage = (entry: BridgeMessageEntry): void => {
|
|
77
|
+
bridgeMessages.push(entry)
|
|
78
|
+
if (bridgeMessages.length > BRIDGE_MSG_CAP) {
|
|
79
|
+
bridgeMessages.shift()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const getBridgeMessages = (
|
|
84
|
+
filter: BridgeMessageFilter = {},
|
|
85
|
+
): BridgeMessageEntry[] => {
|
|
86
|
+
return bridgeMessages.filter((entry) => {
|
|
87
|
+
if (
|
|
88
|
+
filter.direction !== undefined &&
|
|
89
|
+
filter.direction !== "all" &&
|
|
90
|
+
entry.direction !== filter.direction
|
|
91
|
+
) {
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
if (filter.channel !== undefined && entry.channel !== filter.channel) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
if (filter.type !== undefined && entry.type !== filter.type) {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
if (filter.sinceMs !== undefined && entry.ts < filter.sinceMs) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
if (
|
|
104
|
+
filter.contentSubstring !== undefined &&
|
|
105
|
+
!JSON.stringify(entry.payload ?? "").includes(filter.contentSubstring)
|
|
106
|
+
) {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
return true
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const clearBridgeMessages = (): void => {
|
|
114
|
+
bridgeMessages.length = 0
|
|
115
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendBridgeMessage,
|
|
3
|
+
appendServiceLog,
|
|
4
|
+
type ServiceLogLevel,
|
|
5
|
+
} from "./bridge-log-store"
|
|
6
|
+
|
|
7
|
+
export const WS_BACKOFF_DELAYS_MS = [
|
|
8
|
+
1000, 2000, 4000, 8000, 16000, 30000,
|
|
9
|
+
] as const
|
|
10
|
+
|
|
11
|
+
export const WS_MAX_ATTEMPTS = 10
|
|
12
|
+
|
|
13
|
+
export const computeNextBackoff = (attempt: number): number => {
|
|
14
|
+
if (attempt < 0) return WS_BACKOFF_DELAYS_MS[0]!
|
|
15
|
+
if (attempt >= WS_BACKOFF_DELAYS_MS.length)
|
|
16
|
+
return WS_BACKOFF_DELAYS_MS[WS_BACKOFF_DELAYS_MS.length - 1]!
|
|
17
|
+
return WS_BACKOFF_DELAYS_MS[attempt]!
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WebSocketLike {
|
|
21
|
+
send(data: string): void
|
|
22
|
+
close(): void
|
|
23
|
+
addEventListener?(name: string, cb: (event: unknown) => void): void
|
|
24
|
+
removeEventListener?(name: string, cb: (event: unknown) => void): void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface WsClientOptions {
|
|
28
|
+
readonly url: string
|
|
29
|
+
readonly token?: string
|
|
30
|
+
readonly onOpen?: () => void
|
|
31
|
+
readonly onMessage?: (data: unknown) => void
|
|
32
|
+
readonly onClose?: () => void
|
|
33
|
+
readonly onFailed?: () => void
|
|
34
|
+
readonly onStatus?: (status: WsStatus) => void
|
|
35
|
+
readonly wsFactory?: (url: string) => WebSocketLike
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type WsStatus =
|
|
39
|
+
| "connecting"
|
|
40
|
+
| "open"
|
|
41
|
+
| "closed"
|
|
42
|
+
| "failed"
|
|
43
|
+
| "authorization-failed"
|
|
44
|
+
|
|
45
|
+
export interface WsClient {
|
|
46
|
+
send(data: string): void
|
|
47
|
+
close(): void
|
|
48
|
+
status(): WsStatus
|
|
49
|
+
attemptCount(): number
|
|
50
|
+
lastError(): string | null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const createWsClient = (options: WsClientOptions): WsClient => {
|
|
54
|
+
let status: WsStatus = "connecting"
|
|
55
|
+
let attempts = 0
|
|
56
|
+
let ws: WebSocketLike | null = null
|
|
57
|
+
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
|
|
58
|
+
let closedByUser = false
|
|
59
|
+
let lastErrorValue: string | null = null
|
|
60
|
+
let openListener: ((event: unknown) => void) | null = null
|
|
61
|
+
let closeListener: ((event: unknown) => void) | null = null
|
|
62
|
+
const messageListeners: Array<(event: unknown) => void> = []
|
|
63
|
+
|
|
64
|
+
const setStatus = (next: WsStatus): void => {
|
|
65
|
+
status = next
|
|
66
|
+
options.onStatus?.(next)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const scheduleReconnect = (): void => {
|
|
70
|
+
if (closedByUser) return
|
|
71
|
+
if (reconnectTimer !== null) clearTimeout(reconnectTimer)
|
|
72
|
+
const delay = computeNextBackoff(Math.max(0, attempts - 1))
|
|
73
|
+
reconnectTimer = setTimeout(() => {
|
|
74
|
+
reconnectTimer = null
|
|
75
|
+
open()
|
|
76
|
+
}, delay)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const onWsOpen = (event: unknown): void => {
|
|
80
|
+
// ponytail: reset attempt counter on successful open so a long-lived
|
|
81
|
+
// emitter can reconnect after a transient blip without permanently
|
|
82
|
+
// burning its WS_MAX_ATTEMPTS budget.
|
|
83
|
+
attempts = 0
|
|
84
|
+
ws?.send(serializeHello(options.token))
|
|
85
|
+
setStatus("open")
|
|
86
|
+
options.onOpen?.()
|
|
87
|
+
void event
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const onWsClose = (event: unknown): void => {
|
|
91
|
+
const closeCode =
|
|
92
|
+
typeof event === "object" && event !== null && "code" in event
|
|
93
|
+
? (event as { code?: unknown }).code
|
|
94
|
+
: undefined
|
|
95
|
+
if (closeCode === 4001) {
|
|
96
|
+
lastErrorValue =
|
|
97
|
+
"Token mismatch — close this window and run sirenodeck config-ui again"
|
|
98
|
+
setStatus("authorization-failed")
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
setStatus("closed")
|
|
102
|
+
options.onClose?.()
|
|
103
|
+
scheduleReconnect()
|
|
104
|
+
void event
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const onWsMessage = (event: unknown): void => {
|
|
108
|
+
const data =
|
|
109
|
+
event instanceof MessageEvent
|
|
110
|
+
? event.data
|
|
111
|
+
: ((event as { data?: unknown })?.data ?? event)
|
|
112
|
+
try {
|
|
113
|
+
const parsed = JSON.parse(String(data)) as {
|
|
114
|
+
type?: string
|
|
115
|
+
channel?: unknown
|
|
116
|
+
level?: string
|
|
117
|
+
msg?: string
|
|
118
|
+
ts?: number
|
|
119
|
+
component?: string
|
|
120
|
+
deckId?: string
|
|
121
|
+
position?: number
|
|
122
|
+
addonName?: string
|
|
123
|
+
gesture?: string
|
|
124
|
+
keyIndex?: number
|
|
125
|
+
}
|
|
126
|
+
appendBridgeMessage({
|
|
127
|
+
ts: Date.now(),
|
|
128
|
+
direction: "received",
|
|
129
|
+
type: parsed.type ?? "unknown",
|
|
130
|
+
channel: extractChannel(parsed),
|
|
131
|
+
payload: parsed,
|
|
132
|
+
})
|
|
133
|
+
if (parsed.type === "service-log") {
|
|
134
|
+
if (
|
|
135
|
+
typeof parsed.msg === "string" &&
|
|
136
|
+
typeof parsed.ts === "number" &&
|
|
137
|
+
typeof parsed.level === "string"
|
|
138
|
+
) {
|
|
139
|
+
appendServiceLog({
|
|
140
|
+
ts: parsed.ts,
|
|
141
|
+
level: parsed.level as ServiceLogLevel,
|
|
142
|
+
msg: parsed.msg,
|
|
143
|
+
...(typeof parsed.component === "string"
|
|
144
|
+
? { component: parsed.component }
|
|
145
|
+
: {}),
|
|
146
|
+
...(typeof parsed.deckId === "string"
|
|
147
|
+
? { deckId: parsed.deckId }
|
|
148
|
+
: {}),
|
|
149
|
+
...(typeof parsed.position === "number"
|
|
150
|
+
? { position: parsed.position }
|
|
151
|
+
: {}),
|
|
152
|
+
...(typeof parsed.addonName === "string"
|
|
153
|
+
? { addonName: parsed.addonName }
|
|
154
|
+
: {}),
|
|
155
|
+
...(parsed.gesture === "tap" ||
|
|
156
|
+
parsed.gesture === "dbl-tap" ||
|
|
157
|
+
parsed.gesture === "hold"
|
|
158
|
+
? { gesture: parsed.gesture }
|
|
159
|
+
: {}),
|
|
160
|
+
...(typeof parsed.keyIndex === "number"
|
|
161
|
+
? { keyIndex: parsed.keyIndex }
|
|
162
|
+
: {}),
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
// ignore unparseable
|
|
168
|
+
}
|
|
169
|
+
options.onMessage?.(data)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const open = (): void => {
|
|
173
|
+
if (closedByUser) return
|
|
174
|
+
if (attempts >= WS_MAX_ATTEMPTS) {
|
|
175
|
+
setStatus("failed")
|
|
176
|
+
options.onFailed?.()
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
attempts += 1
|
|
180
|
+
const factory =
|
|
181
|
+
options.wsFactory ??
|
|
182
|
+
((url: string) => new WebSocket(url) as unknown as WebSocketLike)
|
|
183
|
+
const created = factory(options.url)
|
|
184
|
+
if (created === null || created === undefined) {
|
|
185
|
+
setStatus("failed")
|
|
186
|
+
options.onFailed?.()
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
ws = created
|
|
190
|
+
setStatus("connecting")
|
|
191
|
+
if (typeof created.addEventListener === "function") {
|
|
192
|
+
openListener = onWsOpen
|
|
193
|
+
closeListener = onWsClose
|
|
194
|
+
const messageListener = onWsMessage
|
|
195
|
+
const errorListener = (): void => {
|
|
196
|
+
lastErrorValue = "WebSocket connection error"
|
|
197
|
+
if (attempts >= WS_MAX_ATTEMPTS) setStatus("failed")
|
|
198
|
+
}
|
|
199
|
+
created.addEventListener("open", openListener)
|
|
200
|
+
created.addEventListener("close", closeListener)
|
|
201
|
+
created.addEventListener("message", messageListener)
|
|
202
|
+
created.addEventListener("error", errorListener)
|
|
203
|
+
messageListeners.push(messageListener)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void open()
|
|
208
|
+
|
|
209
|
+
const extractChannel = (parsed: {
|
|
210
|
+
type?: string
|
|
211
|
+
channel?: unknown
|
|
212
|
+
}): string | null => {
|
|
213
|
+
if (parsed.channel === undefined) return null
|
|
214
|
+
if (typeof parsed.channel === "string") return parsed.channel
|
|
215
|
+
return null
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
send(data) {
|
|
220
|
+
try {
|
|
221
|
+
const parsed = JSON.parse(data) as { type?: string; channel?: unknown }
|
|
222
|
+
appendBridgeMessage({
|
|
223
|
+
ts: Date.now(),
|
|
224
|
+
direction: "sent",
|
|
225
|
+
type: parsed.type ?? "unknown",
|
|
226
|
+
channel: extractChannel(parsed),
|
|
227
|
+
payload: parsed,
|
|
228
|
+
})
|
|
229
|
+
if (parsed.type === "service-log") {
|
|
230
|
+
const e = parsed as {
|
|
231
|
+
level?: string
|
|
232
|
+
msg?: string
|
|
233
|
+
ts?: number
|
|
234
|
+
component?: string
|
|
235
|
+
deckId?: string
|
|
236
|
+
position?: number
|
|
237
|
+
addonName?: string
|
|
238
|
+
gesture?: string
|
|
239
|
+
keyIndex?: number
|
|
240
|
+
}
|
|
241
|
+
if (
|
|
242
|
+
typeof e.msg === "string" &&
|
|
243
|
+
typeof e.ts === "number" &&
|
|
244
|
+
typeof e.level === "string"
|
|
245
|
+
) {
|
|
246
|
+
appendServiceLog({
|
|
247
|
+
ts: e.ts,
|
|
248
|
+
level: e.level as ServiceLogLevel,
|
|
249
|
+
msg: e.msg,
|
|
250
|
+
...(typeof e.component === "string"
|
|
251
|
+
? { component: e.component }
|
|
252
|
+
: {}),
|
|
253
|
+
...(typeof e.deckId === "string" ? { deckId: e.deckId } : {}),
|
|
254
|
+
...(typeof e.position === "number"
|
|
255
|
+
? { position: e.position }
|
|
256
|
+
: {}),
|
|
257
|
+
...(typeof e.addonName === "string"
|
|
258
|
+
? { addonName: e.addonName }
|
|
259
|
+
: {}),
|
|
260
|
+
...(e.gesture === "tap" ||
|
|
261
|
+
e.gesture === "dbl-tap" ||
|
|
262
|
+
e.gesture === "hold"
|
|
263
|
+
? { gesture: e.gesture }
|
|
264
|
+
: {}),
|
|
265
|
+
...(typeof e.keyIndex === "number"
|
|
266
|
+
? { keyIndex: e.keyIndex }
|
|
267
|
+
: {}),
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
// ignore unparseable
|
|
273
|
+
}
|
|
274
|
+
if (ws !== null && status === "open") ws.send(data)
|
|
275
|
+
},
|
|
276
|
+
close() {
|
|
277
|
+
closedByUser = true
|
|
278
|
+
if (reconnectTimer !== null) {
|
|
279
|
+
clearTimeout(reconnectTimer)
|
|
280
|
+
reconnectTimer = null
|
|
281
|
+
}
|
|
282
|
+
if (ws !== null && typeof ws.removeEventListener === "function") {
|
|
283
|
+
if (openListener !== null) ws.removeEventListener("open", openListener)
|
|
284
|
+
if (closeListener !== null)
|
|
285
|
+
ws.removeEventListener("close", closeListener)
|
|
286
|
+
for (const ml of messageListeners) ws.removeEventListener("message", ml)
|
|
287
|
+
}
|
|
288
|
+
ws?.close()
|
|
289
|
+
setStatus("closed")
|
|
290
|
+
},
|
|
291
|
+
status: () => status,
|
|
292
|
+
attemptCount: () => attempts,
|
|
293
|
+
lastError: () => lastErrorValue,
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export const serializeHello = (token?: string): string => {
|
|
298
|
+
return JSON.stringify({
|
|
299
|
+
type: "hello",
|
|
300
|
+
version: 1,
|
|
301
|
+
...(token !== undefined ? { token } : {}),
|
|
302
|
+
})
|
|
303
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Input, Label, ListBox, Select, TextField } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { parsePlatformMacro } from "@/deck/macro-parse"
|
|
4
|
+
import { MacroPreview } from "./MacroPreview"
|
|
5
|
+
|
|
6
|
+
type MacroParts = {
|
|
7
|
+
fallback: string
|
|
8
|
+
macos: string
|
|
9
|
+
linux: string
|
|
10
|
+
windows: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const parseMacro = (value: string): MacroParts => {
|
|
14
|
+
if (!value.startsWith("macro://"))
|
|
15
|
+
return { fallback: value, macos: "", linux: "", windows: "" }
|
|
16
|
+
const inner = value.slice("macro://".length)
|
|
17
|
+
if (inner.startsWith("{")) {
|
|
18
|
+
try {
|
|
19
|
+
const overrides = JSON.parse(inner) as Record<string, unknown>
|
|
20
|
+
return {
|
|
21
|
+
fallback: typeof overrides.all === "string" ? overrides.all : "",
|
|
22
|
+
macos:
|
|
23
|
+
typeof overrides.macos === "string"
|
|
24
|
+
? overrides.macos
|
|
25
|
+
: typeof overrides.osx === "string"
|
|
26
|
+
? overrides.osx
|
|
27
|
+
: "",
|
|
28
|
+
linux: typeof overrides.linux === "string" ? overrides.linux : "",
|
|
29
|
+
windows: typeof overrides.windows === "string" ? overrides.windows : "",
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
return { fallback: inner, macos: "", linux: "", windows: "" }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const parsed = parsePlatformMacro(inner)
|
|
37
|
+
return {
|
|
38
|
+
fallback: parsed.fallback,
|
|
39
|
+
macos: parsed.overrides.get("macos") ?? "",
|
|
40
|
+
linux: parsed.overrides.get("linux") ?? "",
|
|
41
|
+
windows: parsed.overrides.get("windows") ?? "",
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
return { fallback: "", macos: "", linux: "", windows: "" }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const isValidActionValue = (value: string): boolean => {
|
|
49
|
+
if (!value.startsWith("macro://")) return true
|
|
50
|
+
try {
|
|
51
|
+
parsePlatformMacro(value.slice("macro://".length))
|
|
52
|
+
return true
|
|
53
|
+
} catch {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const buildMacro = (parts: MacroParts): string => {
|
|
59
|
+
if (parts.fallback.trim() === "") return "macro://"
|
|
60
|
+
const overrides = (
|
|
61
|
+
[
|
|
62
|
+
["macos", parts.macos],
|
|
63
|
+
["linux", parts.linux],
|
|
64
|
+
["windows", parts.windows],
|
|
65
|
+
] as const
|
|
66
|
+
)
|
|
67
|
+
.filter(([, command]) => command.trim() !== "")
|
|
68
|
+
.map(([os, command]) => `[${os}:${command}]`)
|
|
69
|
+
.join("")
|
|
70
|
+
return `macro://${overrides}${parts.fallback}`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const ActionValueEditor = ({
|
|
74
|
+
label,
|
|
75
|
+
value,
|
|
76
|
+
onChange,
|
|
77
|
+
}: {
|
|
78
|
+
readonly label: string
|
|
79
|
+
readonly value: string
|
|
80
|
+
readonly onChange: (value: string) => void
|
|
81
|
+
}) => {
|
|
82
|
+
const isMacro = value.startsWith("macro://")
|
|
83
|
+
const macro = parseMacro(value)
|
|
84
|
+
const setMacro = (patch: Partial<MacroParts>): void =>
|
|
85
|
+
onChange(buildMacro({ ...macro, ...patch }))
|
|
86
|
+
const macroFields: Array<{
|
|
87
|
+
label: string
|
|
88
|
+
value: string
|
|
89
|
+
onChange: (value: string) => void
|
|
90
|
+
}> = [
|
|
91
|
+
{
|
|
92
|
+
label: "Default macro",
|
|
93
|
+
value: macro.fallback,
|
|
94
|
+
onChange: (fallback) => setMacro({ fallback }),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: "macOS override",
|
|
98
|
+
value: macro.macos,
|
|
99
|
+
onChange: (macos) => setMacro({ macos }),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
label: "Linux override",
|
|
103
|
+
value: macro.linux,
|
|
104
|
+
onChange: (linux) => setMacro({ linux }),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: "Windows override",
|
|
108
|
+
value: macro.windows,
|
|
109
|
+
onChange: (windows) => setMacro({ windows }),
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div className="grid min-w-0 gap-2 rounded-lg border border-separator bg-neutral-900 p-2">
|
|
115
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
116
|
+
<span className="text-sm font-medium">{label}</span>
|
|
117
|
+
<Select
|
|
118
|
+
aria-label={`${label} kind`}
|
|
119
|
+
selectedKey={isMacro ? "macro" : "command"}
|
|
120
|
+
onSelectionChange={(key) => {
|
|
121
|
+
if (String(key) === "macro" && !isMacro)
|
|
122
|
+
onChange(`macro://${value}`)
|
|
123
|
+
else if (String(key) === "command" && isMacro)
|
|
124
|
+
onChange(macro.fallback)
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<Select.Trigger className="min-w-32">
|
|
128
|
+
<Select.Value />
|
|
129
|
+
<Select.Indicator />
|
|
130
|
+
</Select.Trigger>
|
|
131
|
+
<Select.Popover>
|
|
132
|
+
<ListBox>
|
|
133
|
+
<ListBox.Item id="command" textValue="Command">
|
|
134
|
+
Command
|
|
135
|
+
<ListBox.ItemIndicator />
|
|
136
|
+
</ListBox.Item>
|
|
137
|
+
<ListBox.Item id="macro" textValue="Keyboard macro">
|
|
138
|
+
Keyboard macro
|
|
139
|
+
<ListBox.ItemIndicator />
|
|
140
|
+
</ListBox.Item>
|
|
141
|
+
</ListBox>
|
|
142
|
+
</Select.Popover>
|
|
143
|
+
</Select>
|
|
144
|
+
</div>
|
|
145
|
+
{isMacro ? (
|
|
146
|
+
<div className="grid min-w-0 gap-2">
|
|
147
|
+
{macroFields.map((field) => (
|
|
148
|
+
<TextField
|
|
149
|
+
key={field.label}
|
|
150
|
+
className="grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-2"
|
|
151
|
+
>
|
|
152
|
+
<Label className="min-w-0 break-words">{field.label}</Label>
|
|
153
|
+
<Input
|
|
154
|
+
aria-label={field.label}
|
|
155
|
+
value={field.value}
|
|
156
|
+
spellCheck={false}
|
|
157
|
+
autoCapitalize="off"
|
|
158
|
+
autoCorrect="off"
|
|
159
|
+
onChange={(event) => field.onChange(event.target.value)}
|
|
160
|
+
className="min-w-0 bg-neutral-950 font-mono text-sm"
|
|
161
|
+
/>
|
|
162
|
+
</TextField>
|
|
163
|
+
))}
|
|
164
|
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
|
165
|
+
{(
|
|
166
|
+
[
|
|
167
|
+
["Default", macro.fallback],
|
|
168
|
+
["macOS", macro.macos],
|
|
169
|
+
["Linux", macro.linux],
|
|
170
|
+
["Windows", macro.windows],
|
|
171
|
+
] as const
|
|
172
|
+
)
|
|
173
|
+
.filter(([, command]) => command.trim() !== "")
|
|
174
|
+
.map(([platform, command]) => (
|
|
175
|
+
<div key={platform} className="flex items-center gap-1">
|
|
176
|
+
<span className="text-xs text-muted">{platform}</span>
|
|
177
|
+
<MacroPreview value={command} />
|
|
178
|
+
</div>
|
|
179
|
+
))}
|
|
180
|
+
</div>
|
|
181
|
+
{macro.fallback.trim() === "" && (
|
|
182
|
+
<p className="text-sm text-danger md:col-span-2">
|
|
183
|
+
Add a default macro; platform overrides alone are not sufficient.
|
|
184
|
+
</p>
|
|
185
|
+
)}
|
|
186
|
+
{!isValidActionValue(value) && macro.fallback.trim() !== "" && (
|
|
187
|
+
<p role="alert" className="text-sm text-danger md:col-span-2">
|
|
188
|
+
Check the platform override syntax; each override uses a key
|
|
189
|
+
sequence such as <code>ctrl+c</code>.
|
|
190
|
+
</p>
|
|
191
|
+
)}
|
|
192
|
+
</div>
|
|
193
|
+
) : (
|
|
194
|
+
<TextField className="grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-2">
|
|
195
|
+
<Label className="min-w-0 break-words">{label} command</Label>
|
|
196
|
+
<Input
|
|
197
|
+
aria-label={`${label} command`}
|
|
198
|
+
value={value}
|
|
199
|
+
spellCheck={false}
|
|
200
|
+
autoCapitalize="off"
|
|
201
|
+
autoCorrect="off"
|
|
202
|
+
onChange={(event) => onChange(event.target.value)}
|
|
203
|
+
className="min-w-0 bg-neutral-950 font-mono text-sm"
|
|
204
|
+
/>
|
|
205
|
+
</TextField>
|
|
206
|
+
)}
|
|
207
|
+
</div>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Accordion, Fieldset, Tabs } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { ActionValueEditor } from "./ActionValueEditor"
|
|
4
|
+
|
|
5
|
+
type GestureActions = { tap?: string; dbltap?: string; hold?: string }
|
|
6
|
+
|
|
7
|
+
export const ButtonActionsEditor = ({
|
|
8
|
+
value,
|
|
9
|
+
ownedGestures = [],
|
|
10
|
+
onChange,
|
|
11
|
+
}: {
|
|
12
|
+
readonly value: GestureActions
|
|
13
|
+
readonly ownedGestures?: readonly ("tap" | "dbl-tap" | "hold")[]
|
|
14
|
+
readonly onChange: (value: GestureActions) => void
|
|
15
|
+
}) => {
|
|
16
|
+
const gestures = (
|
|
17
|
+
[
|
|
18
|
+
["tap", "tap", "Tap"],
|
|
19
|
+
["dbl-tap", "dbltap", "Double tap"],
|
|
20
|
+
["hold", "hold", "Hold"],
|
|
21
|
+
] as const
|
|
22
|
+
).filter(([gesture]) => !ownedGestures.includes(gesture))
|
|
23
|
+
|
|
24
|
+
if (gestures.length === 0) return null
|
|
25
|
+
|
|
26
|
+
const changeGesture = (
|
|
27
|
+
key: "tap" | "dbltap" | "hold",
|
|
28
|
+
next: string,
|
|
29
|
+
): void => {
|
|
30
|
+
const actions = { ...value }
|
|
31
|
+
if (next === "") delete actions[key]
|
|
32
|
+
else actions[key] = next
|
|
33
|
+
onChange(actions)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Accordion variant="surface" className="w-full">
|
|
38
|
+
<Accordion.Item
|
|
39
|
+
id="gesture-actions"
|
|
40
|
+
className="rounded-lg bg-neutral-800"
|
|
41
|
+
>
|
|
42
|
+
<Accordion.Heading>
|
|
43
|
+
<Accordion.Trigger>
|
|
44
|
+
Gesture actions
|
|
45
|
+
<Accordion.Indicator />
|
|
46
|
+
</Accordion.Trigger>
|
|
47
|
+
</Accordion.Heading>
|
|
48
|
+
<Accordion.Panel>
|
|
49
|
+
<Accordion.Body className="bg-neutral-800">
|
|
50
|
+
<Fieldset className="grid gap-3 border-0 p-0">
|
|
51
|
+
<Fieldset.Legend className="sr-only">
|
|
52
|
+
Gesture actions
|
|
53
|
+
</Fieldset.Legend>
|
|
54
|
+
<Tabs
|
|
55
|
+
aria-label="Gesture actions"
|
|
56
|
+
defaultSelectedKey={gestures[0]![1]}
|
|
57
|
+
>
|
|
58
|
+
<Tabs.ListContainer>
|
|
59
|
+
<Tabs.List>
|
|
60
|
+
{gestures.map(([, key, label]) => (
|
|
61
|
+
<Tabs.Tab key={key} id={key}>
|
|
62
|
+
{label}
|
|
63
|
+
<Tabs.Indicator />
|
|
64
|
+
</Tabs.Tab>
|
|
65
|
+
))}
|
|
66
|
+
</Tabs.List>
|
|
67
|
+
</Tabs.ListContainer>
|
|
68
|
+
{gestures.map(([, key, label]) => (
|
|
69
|
+
<Tabs.Panel key={key} id={key}>
|
|
70
|
+
<ActionValueEditor
|
|
71
|
+
label={label}
|
|
72
|
+
value={value[key] ?? ""}
|
|
73
|
+
onChange={(next) => changeGesture(key, next)}
|
|
74
|
+
/>
|
|
75
|
+
</Tabs.Panel>
|
|
76
|
+
))}
|
|
77
|
+
</Tabs>
|
|
78
|
+
</Fieldset>
|
|
79
|
+
</Accordion.Body>
|
|
80
|
+
</Accordion.Panel>
|
|
81
|
+
</Accordion.Item>
|
|
82
|
+
</Accordion>
|
|
83
|
+
)
|
|
84
|
+
}
|