diff --git a/web/app.ts b/web/app.ts index 55f4b28..a05ccc2 100644 --- a/web/app.ts +++ b/web/app.ts @@ -128,19 +128,19 @@ function connectWS(): void { micBtn.disabled = false; }; ws.onmessage = (e: MessageEvent) => handleServerMsg(e.data); -ws.onclose = () => { - state.connected = false; - state.ws = null; - micBtn.disabled = true; - if (state.recording) stopRecording(); - if (state.pendingStart) { - state.abortController?.abort(); - state.pendingStart = false; - micBtn.classList.remove("recording"); - } - setStatus("disconnected", "已断开"); - scheduleReconnect(); -}; + ws.onclose = () => { + state.connected = false; + state.ws = null; + micBtn.disabled = true; + if (state.recording) stopRecording(); + if (state.pendingStart) { + state.abortController?.abort(); + state.pendingStart = false; + micBtn.classList.remove("recording"); + } + setStatus("disconnected", "已断开"); + scheduleReconnect(); + }; ws.onerror = () => ws.close(); state.ws = ws; } @@ -201,11 +201,14 @@ function showToast(msg: string): void { const toast = q("#toast"); toast.textContent = msg; toast.classList.add("show"); - const timer = (toast as HTMLElement & { _timer?: ReturnType })._timer; + const timer = ( + toast as HTMLElement & { _timer?: ReturnType } + )._timer; if (timer) clearTimeout(timer); - (toast as HTMLElement & { _timer?: ReturnType })._timer = setTimeout(() => { - toast.classList.remove("show"); - }, 2000); + (toast as HTMLElement & { _timer?: ReturnType })._timer = + setTimeout(() => { + toast.classList.remove("show"); + }, 2000); } // ── Audio pipeline ── async function initAudio(): Promise { @@ -331,8 +334,10 @@ function renderHistory(): void { return; } (historyEmpty as HTMLElement).style.display = "none"; - for (const item of items) { + for (let i = 0; i < items.length; i++) { + const item = items[i]; const li = document.createElement("li"); + li.style.setProperty("--i", String(Math.min(i, 10))); li.innerHTML = `${escapeHtml(item.text)}` + `${formatTime(item.ts)}`;