ext: state-driven toolbar icon, restyled popup
This commit is contained in:
@@ -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); });
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ const API = "http://127.0.0.1:18765";
|
|||||||
let recorder, audioContext, tabStream, micStream, uploadQueue = Promise.resolve(), recordingName;
|
let recorder, audioContext, tabStream, micStream, uploadQueue = Promise.resolve(), recordingName;
|
||||||
// state: idle | recording | transcribing | done | error ; popup polls it
|
// state: idle | recording | transcribing | done | error ; popup polls it
|
||||||
const recorderState = { state: "idle", name: "", t0: 0, t1: 0, chunks: 0, mic: false, text: "" };
|
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.
|
// Messages from popup.js / teams.js are addressed with to:"off"; other messages are ignored.
|
||||||
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
||||||
|
|||||||
+29
-5
@@ -1,10 +1,34 @@
|
|||||||
<!-- Extension popup: Start/Stop button, mic-grant link, status line and transcript view. -->
|
<!-- Extension popup: Start/Stop button, mic-grant link, status line and transcript view. -->
|
||||||
<body style="width:380px;font:13px sans-serif">
|
<meta charset="utf-8">
|
||||||
<!-- mic.html opens in a new tab so the permission prompt can appear; needed once. -->
|
<style>
|
||||||
<button id="go">Start</button> <a href="mic.html" target="_blank">grant mic (once)</a>
|
:root { --accent: #64748b; }
|
||||||
|
body { width: 380px; margin: 0; padding: 16px; box-sizing: border-box; font: 13px/1.4 system-ui, "Segoe UI", sans-serif; color: #0f172a; background: #f8fafc; }
|
||||||
|
body[data-state=recording] { --accent: #dc2626; }
|
||||||
|
body[data-state=transcribing] { --accent: #2563eb; }
|
||||||
|
body[data-state=done] { --accent: #16a34a; }
|
||||||
|
body[data-state=error] { --accent: #d97706; }
|
||||||
|
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; }
|
||||||
|
@keyframes pulse { 50% { opacity: .25; } }
|
||||||
|
#go { width: 100%; padding: 10px; border: 0; border-radius: 8px; font: inherit; font-weight: 600; color: #fff; background: var(--accent); cursor: pointer; transition: filter .15s; }
|
||||||
|
#go:hover:not(:disabled) { filter: brightness(1.1); }
|
||||||
|
#go:disabled { opacity: .5; cursor: default; }
|
||||||
|
body[data-state=idle] #go, body[data-state=done] #go, body[data-state=error] #go { background: #0f172a; }
|
||||||
|
#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; }
|
||||||
|
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>
|
||||||
|
<!-- Start/Stop; popup.js drives it. -->
|
||||||
|
<button id="go">Start</button>
|
||||||
<!-- Status line, filled by popup.js. -->
|
<!-- Status line, filled by popup.js. -->
|
||||||
<div id="st"></div>
|
<div id="st"></div>
|
||||||
<!-- Transcript/result text returned by the recorder. -->
|
<!-- Transcript/result text returned by the recorder. -->
|
||||||
<pre id="txt" style="white-space:pre-wrap;max-height:300px;overflow:auto"></pre>
|
<pre id="txt"></pre>
|
||||||
<!-- popup.js drives the UI. -->
|
<!-- mic.html opens in a new tab so the permission prompt can appear; needed once. -->
|
||||||
|
<a href="mic.html" target="_blank">grant mic (once)</a>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
|
</body>
|
||||||
|
|||||||
+2
-1
@@ -11,6 +11,7 @@ let recorderState = { state: "idle" }, lastError = "";
|
|||||||
// Refresh the button and status line from state recorderState.
|
// Refresh the button and status line from state recorderState.
|
||||||
function render() {
|
function render() {
|
||||||
const goButton = byId("go"), statusLine = byId("st");
|
const goButton = byId("go"), statusLine = byId("st");
|
||||||
|
document.body.dataset.state = recorderState.state;
|
||||||
// Pipeline busy after stop: no new start until it finishes.
|
// Pipeline busy after stop: no new start until it finishes.
|
||||||
goButton.disabled = recorderState.state === "transcribing";
|
goButton.disabled = recorderState.state === "transcribing";
|
||||||
// Button doubles as Stop while recording.
|
// 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.
|
// 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(() => {});
|
chrome.tabs.sendMessage(activeTab.id, { cmd: "cap-start" }).catch(() => {});
|
||||||
// Any failure is shown in the status line.
|
// 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();
|
render(); poll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user