ext: /health check blocks recording when the backend is offline, strobing offline alarm in popup
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Teams Whisper Recorder",
|
||||
"version": "1.1",
|
||||
"version": "1.2",
|
||||
"description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server",
|
||||
"permissions": ["tabCapture", "offscreen", "activeTab", "tabs", "declarativeNetRequest"],
|
||||
"host_permissions": ["http://127.0.0.1:18765/*", "https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"],
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
body[data-state=transcribing] { --accent: #2563eb; }
|
||||
body[data-state=done] { --accent: #16a34a; }
|
||||
body[data-state=error] { --accent: #d97706; }
|
||||
body[data-state=offline] { --accent: #dc2626; }
|
||||
#off { margin-bottom: 12px; padding: 12px 14px; border-radius: 8px; background: #fef2f2; border: 2px solid #dc2626; color: #7f1d1d; }
|
||||
#off b { display: block; margin-bottom: 4px; font-size: 15px; color: #b91c1c; }
|
||||
#off ol { margin: 8px 0 0; padding-left: 20px; }
|
||||
body[data-state=offline] #st, body[data-state=offline] #txt { display: none; }
|
||||
body[data-state=offline] #go:disabled { opacity: 1; background: #fecaca; color: #991b1b; }
|
||||
/* Offline alarm: banner, button and dot strobe red/white. 0.4 s per cycle = 2.5 flashes/s, under the 3/s photosensitivity limit.
|
||||
No prefers-reduced-motion opt-out on purpose: Windows with animations off reports "reduce" and would hide the alarm. */
|
||||
body[data-state=offline] #off { animation: strobe .4s steps(1) infinite; }
|
||||
body[data-state=offline] #go:disabled, body[data-state=offline] .dot { animation: strobe .4s steps(1) infinite reverse; }
|
||||
@keyframes strobe { 0% { background: #dc2626; color: #fff; border-color: #fff; } 50% { background: #fff; color: #b91c1c; border-color: #dc2626; } }
|
||||
body[data-state=offline] #off b { color: inherit; }
|
||||
h1 { margin: 0 0 12px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
|
||||
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
|
||||
body[data-state=recording] .dot { animation: pulse 1.2s infinite; }
|
||||
@@ -18,14 +30,27 @@
|
||||
#st { margin-top: 12px; padding: 8px 10px; background: #fff; border: 1px solid #e2e8f0; border-left: 3px solid var(--accent); border-radius: 6px; word-break: break-word; }
|
||||
#txt { margin: 12px 0 0; padding: 10px; white-space: pre-wrap; max-height: 260px; overflow: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; font: 12px/1.45 ui-monospace, Consolas, monospace; }
|
||||
#txt:empty { display: none; }
|
||||
#srv { margin-top: 8px; font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; }
|
||||
#srv::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
|
||||
#srv[data-ok=true]::before { background: #16a34a; }
|
||||
#srv[data-ok=false] { color: #dc2626; font-weight: 600; }
|
||||
#srv[data-ok=false]::before { background: #dc2626; }
|
||||
a { display: inline-block; margin-top: 12px; color: #475569; font-size: 12px; }
|
||||
</style>
|
||||
<body data-state="idle">
|
||||
<h1><span class="dot"></span>Teams Whisper</h1>
|
||||
<!-- Shown by popup.js when /health fails and nothing is recording. -->
|
||||
<div id="off" hidden>
|
||||
<b>Backend offline. Recording is NOT possible.</b>
|
||||
The Teams Whisper server (127.0.0.1:18765) is not running, so nothing would be saved.
|
||||
<ol><li>Open Pinokio, then Teams Whisper, then press <b style="display:inline;font-size:inherit">Start</b>.</li><li>Wait until the dot below turns green.</li><li>Press Start here again.</li></ol>
|
||||
</div>
|
||||
<!-- Start/Stop; popup.js drives it. -->
|
||||
<button id="go">Start</button>
|
||||
<!-- Status line, filled by popup.js. -->
|
||||
<div id="st"></div>
|
||||
<!-- Backend health (/health), refreshed every second by popup.js. -->
|
||||
<div id="srv"></div>
|
||||
<!-- Transcript/result text returned by the recorder. -->
|
||||
<pre id="txt"></pre>
|
||||
<!-- mic.html opens in a new tab so the permission prompt can appear; needed once. -->
|
||||
|
||||
+17
-6
@@ -6,16 +6,24 @@ const sendToOffscreen = message => chrome.runtime.sendMessage({ to: "off", ...me
|
||||
// Format milliseconds as m:ss.
|
||||
const formatElapsed = milliseconds => { const totalSeconds = Math.floor(milliseconds / 1000); return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, "0")}`; };
|
||||
// Last error shown when there is no offscreen document to report it.
|
||||
let recorderState = { state: "idle" }, lastError = "";
|
||||
let recorderState = { state: "idle" }, lastError = "", serverOk = null;
|
||||
// Backend liveness (server.py /health); false on any error or after 1.5 s.
|
||||
const serverUp = () => fetch("http://127.0.0.1:18765/health", { signal: AbortSignal.timeout(1500) }).then(response => response.ok, () => false);
|
||||
|
||||
// Refresh the button and status line from state recorderState.
|
||||
function render() {
|
||||
const goButton = byId("go"), statusLine = byId("st");
|
||||
document.body.dataset.state = recorderState.state;
|
||||
// Backend down and not mid-recording: starting is impossible, the offline banner replaces the status line.
|
||||
const offline = serverOk === false && recorderState.state !== "recording";
|
||||
document.body.dataset.state = offline ? "offline" : recorderState.state;
|
||||
byId("off").hidden = !offline;
|
||||
// Pipeline busy after stop: no new start until it finishes.
|
||||
goButton.disabled = recorderState.state === "transcribing";
|
||||
goButton.disabled = offline || recorderState.state === "transcribing";
|
||||
// Backend indicator under the button.
|
||||
byId("srv").dataset.ok = serverOk ?? "";
|
||||
byId("srv").textContent = serverOk == null ? "server: checking..." : serverOk ? "server: online" : "server: OFFLINE";
|
||||
// Button doubles as Stop while recording.
|
||||
goButton.textContent = recorderState.state === "recording" ? "Stop + transcribe" : "Start";
|
||||
goButton.textContent = offline ? "Recording blocked: server offline" : recorderState.state === "recording" ? "Stop + transcribe" : "Start";
|
||||
// Status line text per recorder state.
|
||||
statusLine.textContent = {
|
||||
idle: "idle - open a Teams tab and press Start",
|
||||
@@ -30,8 +38,9 @@ function render() {
|
||||
|
||||
// Poll the recorder state every second.
|
||||
async function poll() {
|
||||
// Offscreen doc exists: ask it for its state. Otherwise show the last error, or idle.
|
||||
if (await chrome.offscreen.hasDocument()) recorderState = (await sendToOffscreen({ cmd: "status" })) || recorderState; else recorderState = lastError ? { state: "error", text: lastError } : { state: "idle" };
|
||||
// A failed Start wins; else ask the offscreen doc (if any) for its state, or show idle.
|
||||
recorderState = lastError ? { state: "error", text: lastError } : (await chrome.offscreen.hasDocument()) ? (await sendToOffscreen({ cmd: "status" })) || recorderState : { state: "idle" };
|
||||
serverOk = await serverUp();
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -54,6 +63,8 @@ byId("go").onclick = async () => {
|
||||
if (activeTab.url?.startsWith("chrome-extension:")) throw new Error("This is the extension's own page. Switch to the Teams tab, then click the icon.");
|
||||
// Stream id that the offscreen document later passes to getUserMedia.
|
||||
const streamId = await chrome.tabCapture.getMediaStreamId({ targetTabId: activeTab.id });
|
||||
// Health check before recording: backend down = nothing would be saved, so show the offline banner and stop here.
|
||||
if (!(serverOk = await serverUp())) return render();
|
||||
// Create the offscreen document once; it stays alive while recording.
|
||||
if (!(await chrome.offscreen.hasDocument()))
|
||||
await chrome.offscreen.createDocument({ url: "offscreen.html", reasons: ["USER_MEDIA"], justification: "record tab" });
|
||||
|
||||
Reference in New Issue
Block a user