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); });
|
||||
|
||||
Reference in New Issue
Block a user