-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathobs-dock.html
More file actions
430 lines (373 loc) · 14 KB
/
Copy pathobs-dock.html
File metadata and controls
430 lines (373 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LyricDisplay Dock</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #070a12;
color: #f8fafc;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
background: #070a12;
}
main {
display: flex;
min-height: 100vh;
flex-direction: column;
justify-content: center;
gap: 14px;
padding: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
}
.brand img {
height: 34px;
width: 34px;
border-radius: 8px;
}
h1 {
margin: 0;
font-size: 18px;
line-height: 1.2;
}
.beta-label {
display: inline-flex;
transform: translateY(-1px);
border: 1px solid rgba(96, 165, 250, 0.45);
border-radius: 999px;
background: rgba(59, 130, 246, 0.16);
color: #bfdbfe;
padding: 2px 6px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0;
line-height: 1;
text-transform: uppercase;
}
p {
margin: 0;
color: #9ca3af;
font-size: 13px;
line-height: 1.5;
}
.status,
.dev-panel {
border: 1px solid #1f2937;
border-radius: 8px;
background: #111827;
color: #d1d5db;
}
.status {
min-height: 44px;
padding: 10px 12px;
font-size: 13px;
}
.status.ready {
border-color: #16a34a;
color: #bbf7d0;
}
.status.error {
border-color: #dc2626;
color: #fecaca;
}
.status.pending {
border-color: #2563eb;
color: #bfdbfe;
}
.actions {
display: grid;
gap: 10px;
}
[hidden] {
display: none !important;
}
button,
.button-link {
display: inline-flex;
min-height: 42px;
width: 100%;
align-items: center;
justify-content: center;
border: 0;
border-radius: 8px;
background: #2563eb;
color: #ffffff;
cursor: pointer;
font: inherit;
font-size: 14px;
font-weight: 700;
text-decoration: none;
}
button.secondary,
.button-link.secondary {
border: 1px solid #374151;
background: #111827;
color: #e5e7eb;
}
button:disabled {
cursor: wait;
opacity: 0.75;
}
.button-link[aria-disabled="true"] {
cursor: wait;
opacity: 0.75;
}
.dev-panel {
display: none;
padding: 10px 12px;
}
body.dev-mode .dev-panel {
display: block;
}
.dev-command {
margin-top: 6px;
display: block;
color: #bfdbfe;
font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
font-size: 12px;
word-break: break-all;
}
</style>
</head>
<body>
<main>
<div class="brand">
<img id="appIcon" src="./LyricDisplay-icon.png" alt="" />
<div>
<h1>LyricDisplay Dock <span class="beta-label">Beta</span></h1>
<p>Open the controller when Dock Mode is ready.</p>
</div>
</div>
<div id="status" class="status">Checking LyricDisplay...</div>
<div id="devPanel" class="dev-panel">
<p>
Development mode uses this command from the app folder:
<code class="dev-command">npm run electron-dev:headless</code>
</p>
</div>
<div class="actions">
<a id="startLink" class="button-link" href="#" aria-disabled="true">Open Controller</a>
<button id="startRuntimeButton" class="secondary" type="button" hidden>Switch to Dock Mode</button>
<button id="openDesktopButton" class="secondary" type="button" hidden>Switch to Desktop Mode</button>
</div>
</main>
<script>
const statusEl = document.getElementById('status');
const startLink = document.getElementById('startLink');
const startRuntimeButton = document.getElementById('startRuntimeButton');
const openDesktopButton = document.getElementById('openDesktopButton');
const iconEl = document.getElementById('appIcon');
const params = new URLSearchParams(window.location.search);
const isHttpVitePage = window.location.protocol.startsWith('http') && window.location.port === '5173';
const devOrigin = 'http://127.0.0.1:5173';
const productionDockUrl = 'http://127.0.0.1:4000/#/obs-dock';
const devDockUrl = `${devOrigin}/?dock=obs&clientType=obsDock`;
const readyUrl = 'http://127.0.0.1:4000/api/health/ready';
const capabilitiesUrl = 'http://127.0.0.1:4000/api/app/capabilities';
const switchToDockModeUrl = 'http://127.0.0.1:4000/api/app/switch-to-dock-mode';
const switchToDesktopModeUrl = 'http://127.0.0.1:4000/api/app/switch-to-desktop-mode';
const devReadyUrl = devDockUrl;
const isWindowsPlatform = /win/i.test(`${navigator.platform || ''} ${navigator.userAgent || ''}`);
let checking = false;
let controllerReady = false;
let devMode = params.get('mode') === 'dev' || isHttpVitePage;
iconEl.addEventListener('error', () => {
if (!iconEl.src.endsWith('/public/LyricDisplay-icon.png')) {
iconEl.src = './public/LyricDisplay-icon.png';
}
});
const setStatus = (message, className = '') => {
statusEl.className = `status ${className}`.trim();
statusEl.textContent = message;
};
const getControllerUrl = () => devMode ? devDockUrl : productionDockUrl;
const getDockModeNotRunningMessage = () => isWindowsPlatform
? 'Dock Mode is not running. Start LyricDisplay Dock Mode from the Start menu, open LyricDisplay and switch to Dock Mode, or enable Start at Sign-In.'
: 'Dock Mode is not running. Open LyricDisplay and switch to Dock Mode, or enable Start at Sign-In.';
const setControllerLinkReady = (ready) => {
controllerReady = Boolean(ready);
const url = getControllerUrl();
startLink.href = controllerReady ? url : '#';
startLink.setAttribute('aria-disabled', controllerReady ? 'false' : 'true');
startRuntimeButton.hidden = devMode || controllerReady;
startRuntimeButton.disabled = false;
startRuntimeButton.textContent = 'Switch to Dock Mode';
};
const setDevMode = (enabled) => {
devMode = Boolean(enabled);
document.body.classList.toggle('dev-mode', devMode);
startLink.textContent = 'Open Controller';
setControllerLinkReady(false);
setStatus(devMode
? 'Start the development Dock Mode command, then open the controller.'
: 'Open the controller when Dock Mode is ready.'
);
};
const canFetch = async (url, predicate = null) => {
const controller = new AbortController();
const timeout = window.setTimeout(() => controller.abort(), 2500);
try {
const response = await fetch(url, { cache: 'no-store', signal: controller.signal });
if (!response.ok) return false;
if (!predicate) return true;
const payload = await response.json();
return predicate(payload);
} catch {
return false;
} finally {
window.clearTimeout(timeout);
}
};
const canReachNoCors = async (url) => {
const controller = new AbortController();
const timeout = window.setTimeout(() => controller.abort(), 2500);
try {
await fetch(url, { cache: 'no-store', mode: 'no-cors', signal: controller.signal });
return true;
} catch {
return false;
} finally {
window.clearTimeout(timeout);
}
};
const checkBackendReady = () => canFetch(
readyUrl,
(payload) => payload && payload.status === 'ready' && payload.serverListening
);
const getBackendCapabilities = async () => {
const controller = new AbortController();
const timeout = window.setTimeout(() => controller.abort(), 2500);
try {
const response = await fetch(capabilitiesUrl, { cache: 'no-store', signal: controller.signal });
if (!response.ok) return null;
return await response.json();
} catch {
return null;
} finally {
window.clearTimeout(timeout);
}
};
const checkRuntimeReady = async () => {
const backendReady = await checkBackendReady();
const capabilities = backendReady ? await getBackendCapabilities() : null;
const dockAuthReady = Boolean(capabilities?.obsDockLocalAuth);
const devReady = devMode ? await canReachNoCors(devReadyUrl) : true;
const desktopSwitchAvailable = Boolean(capabilities?.switchToDesktopMode);
return { ready: backendReady && dockAuthReady && devReady, backendReady, dockAuthReady, devReady, desktopSwitchAvailable };
};
const refreshControllerReadiness = async () => {
if (checking) return controllerReady;
checking = true;
startLink.setAttribute('aria-disabled', 'true');
setStatus(devMode ? 'Checking the development session...' : 'Checking Dock Mode...', 'pending');
const result = await checkRuntimeReady();
openDesktopButton.hidden = !(result.backendReady && result.dockAuthReady && result.desktopSwitchAvailable);
if (result.ready) {
setControllerLinkReady(true);
setStatus('Dock Mode is ready. Open the controller when ready.', 'ready');
checking = false;
return true;
}
setControllerLinkReady(false);
if (devMode) {
if (result.backendReady && !result.dockAuthReady) {
setStatus('LyricDisplay is running in normal development mode. Stop it, then run npm run electron-dev:headless.', 'error');
} else if (result.backendReady && !result.devReady) {
setStatus('The app service is ready, but the development page is not available. Run npm run electron-dev:headless.', 'error');
} else if (!result.backendReady && result.devReady) {
setStatus('The development page is available, but LyricDisplay is not ready yet. Run npm run electron-dev:headless.', 'error');
} else {
setStatus('Development Dock Mode is not ready. Run npm run electron-dev:headless, then try again.', 'error');
}
} else {
startRuntimeButton.hidden = false;
setStatus(result.backendReady && !result.dockAuthReady
? 'LyricDisplay is open normally. Click Switch to Dock Mode and confirm the switch in LyricDisplay.'
: getDockModeNotRunningMessage(),
'error'
);
startRuntimeButton.disabled = false;
startRuntimeButton.textContent = result.backendReady ? 'Switch to Dock Mode' : 'Check Again';
}
checking = false;
return false;
};
const openDesktopApp = async () => {
setStatus('Switching to desktop mode...', 'pending');
try {
const response = await fetch(switchToDesktopModeUrl, {
method: 'POST',
cache: 'no-store'
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
setStatus('LyricDisplay is restarting in desktop mode.', 'ready');
} catch {
setStatus('Could not switch to desktop mode. Use the LyricDisplay tray menu to open or quit Dock Mode.', 'error');
}
};
const sleep = (ms) => new Promise((resolve) => window.setTimeout(resolve, ms));
const switchToDockMode = async () => {
if (devMode) return;
const current = await checkRuntimeReady();
if (current.ready) {
setControllerLinkReady(true);
setStatus('Dock Mode is ready. Open the controller when ready.', 'ready');
return;
}
if (!current.backendReady) {
setControllerLinkReady(false);
startRuntimeButton.disabled = false;
startRuntimeButton.textContent = 'Check Again';
setStatus(getDockModeNotRunningMessage(), 'error');
return;
}
setStatus('Asking LyricDisplay to switch to Dock Mode. Confirm the switch in LyricDisplay.', 'pending');
try {
const response = await fetch(switchToDockModeUrl, {
method: 'POST',
cache: 'no-store'
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
} catch {
setStatus('Could not ask LyricDisplay to switch to Dock Mode. Open LyricDisplay and switch from there.', 'error');
return;
}
for (let attempt = 0; attempt < 18; attempt += 1) {
await sleep(1000);
const result = await checkRuntimeReady();
if (result.ready) {
setControllerLinkReady(true);
setStatus('Dock Mode is ready. Open the controller when ready.', 'ready');
return;
}
}
setControllerLinkReady(false);
setStatus('Dock Mode is not ready yet. If LyricDisplay asked for confirmation, accept it, then try again.', 'error');
};
startLink.addEventListener('click', async (event) => {
if (controllerReady) return;
event.preventDefault();
const ready = await refreshControllerReadiness();
if (ready) {
setStatus('Dock Mode is ready. Click Open Controller again.', 'ready');
}
});
startRuntimeButton.addEventListener('click', switchToDockMode);
openDesktopButton.addEventListener('click', openDesktopApp);
setDevMode(devMode);
refreshControllerReadiness();
</script>
</body>
</html>