-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.html
More file actions
420 lines (376 loc) · 13.5 KB
/
overlay.html
File metadata and controls
420 lines (376 loc) · 13.5 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
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
/>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: transparent;
user-select: none;
-webkit-app-region: drag; /* draggable if needed, but usually static */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<!-- Pill Container -->
<div
class="bg-[#181818] rounded-full px-2 flex items-center justify-between gap-1 shadow-2xl transition-all duration-200 h-full w-full border border-white/10"
id="pill"
>
<!-- Cancel Button (X) - Left Side -->
<div
id="cancel-btn"
class="hidden h-7 w-7 flex items-center justify-center rounded-full bg-white/10 hover:bg-red-500/80 text-white transition-all cursor-pointer flex-shrink-0 shadow-sm"
style="-webkit-app-region: no-drag"
title="Cancel Transcription"
>
<i class="fa-solid fa-xmark text-xs"></i>
</div>
<!-- Center Content: Waveform + Spinner + AI -->
<div class="flex-1 flex items-center justify-center relative">
<!-- Waveform Bars - Voice Responsive -->
<div id="waveform" class="flex items-center gap-[3px] h-full">
<div
class="bar w-[3px] rounded-full h-2"
style="
background: linear-gradient(
to top,
#fff 0%,
rgba(255, 255, 255, 0.8) 100%
);
transition:
height 50ms cubic-bezier(0.4, 0, 0.2, 1),
transform 50ms ease-out;
"
></div>
<div
class="bar w-[3px] rounded-full h-3"
style="
background: linear-gradient(
to top,
#fff 0%,
rgba(255, 255, 255, 0.85) 100%
);
transition:
height 50ms cubic-bezier(0.4, 0, 0.2, 1),
transform 50ms ease-out;
"
></div>
<div
class="bar w-[3px] rounded-full h-5"
style="
background: linear-gradient(
to top,
#fff 0%,
rgba(255, 255, 255, 0.9) 100%
);
transition:
height 50ms cubic-bezier(0.4, 0, 0.2, 1),
transform 50ms ease-out;
"
></div>
<div
class="bar w-[3px] rounded-full h-3"
style="
background: linear-gradient(
to top,
#fff 0%,
rgba(255, 255, 255, 0.85) 100%
);
transition:
height 50ms cubic-bezier(0.4, 0, 0.2, 1),
transform 50ms ease-out;
"
></div>
<div
class="bar w-[3px] rounded-full h-2"
style="
background: linear-gradient(
to top,
#fff 0%,
rgba(255, 255, 255, 0.8) 100%
);
transition:
height 50ms cubic-bezier(0.4, 0, 0.2, 1),
transform 50ms ease-out;
"
></div>
</div>
<!-- Spinner (Hidden by default) -->
<div id="spinner" class="hidden absolute">
<i
class="fa-solid fa-circle-notch text-white/50 text-sm animate-spin"
></i>
</div>
<!-- Status Text (Hidden by default) -->
<div
id="status-text"
class="hidden absolute text-[10px] text-white/80 font-medium tracking-tight truncate px-1 whitespace-nowrap"
>
Just thinking and working.
</div>
<!-- AI Status Icon (🤖) -->
<div id="ai-icon" class="hidden absolute right-2">
<span class="text-[10px]">🤖</span>
</div>
<!-- Busy Indicator (hidden by default) -->
<div
id="busy-indicator"
class="hidden absolute inset-0 flex items-center justify-center gap-1.5 z-10"
>
<span class="text-sm">⏳</span>
<span class="text-[11px] text-white font-semibold tracking-wide"
>Busy</span
>
</div>
</div>
<!-- Confirm Button (Tick) - Right Side -->
<div
id="confirm-btn"
class="hidden h-7 w-7 flex items-center justify-center rounded-full bg-white hover:bg-green-50 text-black transition-all cursor-pointer shadow-lg flex-shrink-0"
style="-webkit-app-region: no-drag"
title="Finish and Transcribe"
>
<i class="fa-solid fa-check text-xs"></i>
</div>
</div>
<script>
const { ipcRenderer } = require("electron");
const bars = document.querySelectorAll(".bar");
const pill = document.getElementById("pill");
const waveform = document.getElementById("waveform");
const spinner = document.getElementById("spinner");
const statusText = document.getElementById("status-text");
// Track last update time for idle animation
let lastMicUpdate = 0;
let isRecording = false;
let animationFrame = null;
let statusCycleTimeout = null;
const busyIndicator = document.getElementById("busy-indicator");
let busyTimeout = null;
let activeRunCycle = null; // Reference to the current processing cycle function
// Show "Busy" indicator briefly when user tries to interact during AI processing
ipcRenderer.on("show-busy", () => {
// Hide other center content
waveform.classList.add("hidden");
if (spinner) spinner.classList.add("hidden");
if (statusText) statusText.classList.add("hidden");
// Pause the processing cycle to prevent overlap
if (statusCycleTimeout) {
clearTimeout(statusCycleTimeout);
statusCycleTimeout = null;
}
// Show busy indicator
busyIndicator.classList.remove("hidden");
// Clear previous timeout if spamming the key
if (busyTimeout) clearTimeout(busyTimeout);
busyTimeout = setTimeout(() => {
busyIndicator.classList.add("hidden");
// Resume the processing cycle if it was active
if (activeRunCycle) {
activeRunCycle();
} else {
// Recording mode, restore waveform
waveform.classList.remove("hidden");
}
busyTimeout = null;
}, 800);
});
// Wave-like center emphasis pattern
const centerWeight = [0.7, 0.9, 1.0, 0.9, 0.7];
// Update bars with given volume values
function updateBars(volumes) {
bars.forEach((bar, i) => {
const v = Math.max(volumes[i] || 0.08, 0.08);
const weighted = v * centerWeight[i];
// Height range: 4px (min) to 32px (max)
const h = 4 + weighted * 28;
bar.style.height = h + "px";
// Subtle scale for lively feel
const scale = 1 + weighted * 0.15;
bar.style.transform = `scaleY(${scale})`;
});
}
// Idle breathing animation when no mic data
function idleAnimation() {
if (!isRecording) return;
const now = Date.now();
const timeSinceUpdate = now - lastMicUpdate;
// If no mic data for 100ms, show idle animation
if (timeSinceUpdate > 100) {
const t = now / 1000;
const idleVolumes =
bars.length === 5
? [
0.15 + 0.1 * Math.sin(t * 3 + 0),
0.2 + 0.15 * Math.sin(t * 3.5 + 0.5),
0.25 + 0.2 * Math.sin(t * 4 + 1),
0.2 + 0.15 * Math.sin(t * 3.5 + 1.5),
0.15 + 0.1 * Math.sin(t * 3 + 2),
]
: [0.2, 0.25, 0.3, 0.25, 0.2];
updateBars(idleVolumes);
}
animationFrame = requestAnimationFrame(idleAnimation);
}
// Start idle animation when overlay shows
function startIdleAnimation() {
isRecording = true;
lastMicUpdate = 0;
if (!animationFrame) {
idleAnimation();
}
}
// Stop animation
function stopIdleAnimation() {
isRecording = false;
if (animationFrame) {
cancelAnimationFrame(animationFrame);
animationFrame = null;
}
}
// Listen for mic volume data
ipcRenderer.on("mic-volume", (event, volumes) => {
lastMicUpdate = Date.now();
if (Array.isArray(volumes)) {
updateBars(volumes);
} else {
// Single value fallback
const v = Math.max(volumes, 0.1);
const singleVolumes = centerWeight.map((w, i) => {
const jitter = 0.9 + Math.random() * 0.2;
return v * w * jitter;
});
updateBars(singleVolumes);
}
});
// Start animation when overlay becomes visible
// The overlay is shown via showInactive(), detect visibility
const observer = new MutationObserver(() => {
if (
document.visibilityState === "visible" ||
!waveform.classList.contains("hidden")
) {
startIdleAnimation();
}
});
// Auto-start animation on load (overlay is shown when recording starts)
startIdleAnimation();
// Processing states
ipcRenderer.on("processing-start", (event, data) => {
try {
const { hasSelection } = data || {};
console.log("Processing started, selection:", hasSelection);
waveform.classList.add("hidden");
document.getElementById("cancel-btn").classList.add("hidden");
document.getElementById("confirm-btn").classList.add("hidden");
ipcRenderer.send("set-overlay-clickable", false);
if (statusCycleTimeout) clearTimeout(statusCycleTimeout);
const thinkingMsgs = [
"Just thinking and working.",
"Working on it...",
"AI thinking...",
"Formatting result...",
"Polishing response...",
];
const webMsgs = [
"Searching on the web...",
"Analyzing selection...",
"Reading your context...",
"Synthesizing answer...",
"Finding references...",
];
const msgs = hasSelection ? webMsgs : thinkingMsgs;
let msgIndex = 0;
function runCycle() {
// Stage 1: Spinner (1s)
if (spinner) spinner.classList.remove("hidden");
if (statusText) statusText.classList.add("hidden");
statusCycleTimeout = setTimeout(() => {
// Stage 2: Message (1.5s)
if (spinner) spinner.classList.add("hidden");
if (statusText) {
statusText.classList.remove("hidden");
statusText.textContent = msgs[msgIndex % msgs.length];
msgIndex++;
}
statusCycleTimeout = setTimeout(() => {
runCycle();
}, 1500);
}, 1000);
}
activeRunCycle = runCycle;
runCycle();
} catch (err) {
console.error("Error in processing-start:", err);
// Fallback visibility
if (spinner) spinner.classList.remove("hidden");
}
});
ipcRenderer.on("processing-end", () => {
console.log("Processing ended");
activeRunCycle = null;
if (statusCycleTimeout) {
clearTimeout(statusCycleTimeout);
statusCycleTimeout = null;
}
if (busyTimeout) {
clearTimeout(busyTimeout);
busyTimeout = null;
}
busyIndicator.classList.add("hidden");
if (spinner) spinner.classList.add("hidden");
if (statusText) statusText.classList.add("hidden");
if (waveform) waveform.classList.remove("hidden");
ipcRenderer.send("hide-overlay");
});
ipcRenderer.on("set-ai-status", (event, enabled) => {
const aiIcon = document.getElementById("ai-icon");
if (enabled) {
aiIcon.classList.remove("hidden");
} else {
aiIcon.classList.add("hidden");
}
});
// New combined control listener
ipcRenderer.on("set-controls", (event, { showCancel, showConfirm }) => {
const cancelBtn = document.getElementById("cancel-btn");
const confirmBtn = document.getElementById("confirm-btn");
if (showCancel) cancelBtn.classList.remove("hidden");
else cancelBtn.classList.add("hidden");
if (showConfirm) confirmBtn.classList.remove("hidden");
else confirmBtn.classList.add("hidden");
});
// Legacy listener - can be removed or kept as fallback
ipcRenderer.on("show-cancel", (event, show) => {
const cancelBtn = document.getElementById("cancel-btn");
const confirmBtn = document.getElementById("confirm-btn");
if (show) {
cancelBtn.classList.remove("hidden");
confirmBtn.classList.remove("hidden");
} else {
cancelBtn.classList.add("hidden");
confirmBtn.classList.add("hidden");
}
});
document.getElementById("cancel-btn").onclick = () => {
ipcRenderer.send("cancel-recording");
};
document.getElementById("confirm-btn").onclick = () => {
ipcRenderer.send("confirm-recording");
};
</script>
</body>
</html>