diff --git a/app/ext/background.js b/app/ext/background.js index 7a10e76..f6648ea 100644 --- a/app/ext/background.js +++ b/app/ext/background.js @@ -29,3 +29,33 @@ chrome.declarativeNetRequest.updateDynamicRules({ }, }], }); + +// Toolbar icon per recorder state, drawn at runtime (no PNG assets). offscreen.js pushes {to:"bg", state} every second. +const ICON = { + idle: { bg: "#64748b", badge: "" }, + recording: { bg: "#dc2626", badge: "REC" }, + transcribing: { bg: "#2563eb", badge: "..." }, + done: { bg: "#16a34a", badge: "OK" }, + error: { bg: "#d97706", badge: "!" }, +}; +function drawIcon(state) { + const { bg, badge } = ICON[state] || ICON.idle; + const images = {}; + for (const size of [16, 32, 48]) { + const canvas = new OffscreenCanvas(size, size), ctx = canvas.getContext("2d"), c = size / 2; + ctx.fillStyle = bg; ctx.beginPath(); ctx.arc(c, c, c, 0, 2 * Math.PI); ctx.fill(); + ctx.fillStyle = ctx.strokeStyle = "#fff"; ctx.lineWidth = size / 8; ctx.lineCap = "round"; + if (state === "recording") { ctx.beginPath(); ctx.arc(c, c, size * 0.22, 0, 2 * Math.PI); ctx.fill(); } + else if (state === "error") { ctx.fillRect(c - size * 0.07, size * 0.2, size * 0.14, size * 0.38); ctx.fillRect(c - size * 0.07, size * 0.68, size * 0.14, size * 0.14); } + else if (state === "done") { ctx.beginPath(); ctx.moveTo(size * 0.27, c); ctx.lineTo(size * 0.44, size * 0.68); ctx.lineTo(size * 0.74, size * 0.32); ctx.stroke(); } + else if (state === "transcribing") { for (const dx of [-0.24, 0, 0.24]) { ctx.beginPath(); ctx.arc(c + dx * size, c, size * 0.07, 0, 2 * Math.PI); ctx.fill(); } } + else { ctx.beginPath(); ctx.moveTo(size * 0.4, size * 0.28); ctx.lineTo(size * 0.72, c); ctx.lineTo(size * 0.4, size * 0.72); ctx.closePath(); ctx.fill(); } + images[size] = ctx.getImageData(0, 0, size, size); + } + chrome.action.setIcon({ imageData: images }); + chrome.action.setBadgeText({ text: badge }); + chrome.action.setBadgeBackgroundColor({ color: bg }); + chrome.action.setTitle({ title: `Teams Whisper - ${state}` }); +} +drawIcon("idle"); +chrome.runtime.onMessage.addListener(message => { if (message.to === "bg") drawIcon(message.state); }); diff --git a/app/ext/offscreen.js b/app/ext/offscreen.js index 6ab5999..5e8057a 100644 --- a/app/ext/offscreen.js +++ b/app/ext/offscreen.js @@ -4,6 +4,8 @@ const API = "http://127.0.0.1:18765"; let recorder, audioContext, tabStream, micStream, uploadQueue = Promise.resolve(), recordingName; // state: idle | recording | transcribing | done | error ; popup polls it const recorderState = { state: "idle", name: "", t0: 0, t1: 0, chunks: 0, mic: false, text: "" }; +// Toolbar icon follows state; failed uploads while recording show as error. The idle icon is drawn by background.js on startup. +setInterval(() => chrome.runtime.sendMessage({ to: "bg", state: recorderState.state === "recording" && recorderState.failed ? "error" : recorderState.state }), 1000); // Messages from popup.js / teams.js are addressed with to:"off"; other messages are ignored. chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { diff --git a/app/ext/popup.html b/app/ext/popup.html index 7172b06..c58ad92 100644 --- a/app/ext/popup.html +++ b/app/ext/popup.html @@ -1,10 +1,34 @@ - - - grant mic (once) + + + +

Teams Whisper

+ +
-

-
+

+
+grant mic (once)
 
+
diff --git a/app/ext/popup.js b/app/ext/popup.js
index 2f9c9e2..b5b74ec 100644
--- a/app/ext/popup.js
+++ b/app/ext/popup.js
@@ -11,6 +11,7 @@ let recorderState = { state: "idle" }, lastError = "";
 // Refresh the button and status line from state recorderState.
 function render() {
   const goButton = byId("go"), statusLine = byId("st");
+  document.body.dataset.state = recorderState.state;
 // Pipeline busy after stop: no new start until it finishes.
   goButton.disabled = recorderState.state === "transcribing";
 // Button doubles as Stop while recording.
@@ -61,7 +62,7 @@ byId("go").onclick = async () => {
 // Tell teams.js to start its scanners; ignored if the content script is not on this tab.
     chrome.tabs.sendMessage(activeTab.id, { cmd: "cap-start" }).catch(() => {});
 // Any failure is shown in the status line.
-  } catch (error) { lastError = String(error); }
+  } catch (error) { lastError = String(error); chrome.runtime.sendMessage({ to: "bg", state: "error" }); }
   render(); poll();
 };