Show classification progress and results via toolbar icons

This commit is contained in:
Jordan Wages 2025-06-27 00:32:19 -05:00
commit e78478ab9a
2 changed files with 22 additions and 12 deletions

View file

@ -18,14 +18,9 @@ let aiRules = [];
let queue = Promise.resolve();
let queuedCount = 0;
let processing = false;
let iconTimer = null;
function updateActionIcon() {
let path = "resources/img/logo32.png";
if (processing) {
path = "resources/img/status-classifying.png";
} else if (queuedCount > 0) {
path = "resources/img/status-queued.png";
}
function setIcon(path) {
if (browser.browserAction) {
browser.browserAction.setIcon({ path });
}
@ -34,6 +29,20 @@ function updateActionIcon() {
}
}
function updateActionIcon() {
let path = "resources/img/logo32.png";
if (processing || queuedCount > 0) {
path = "resources/img/busy.png";
}
setIcon(path);
}
function showTransientIcon(path, delay = 1500) {
clearTimeout(iconTimer);
setIcon(path);
iconTimer = setTimeout(updateActionIcon, delay);
}
async function sha256Hex(str) {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
return Array.from(new Uint8Array(buf), b => b.toString(16).padStart(2, '0')).join('');
@ -125,11 +134,12 @@ async function applyAiRules(idsInput) {
}
}
}
} catch (e) {
logger.aiLog("failed to apply AI rules", { level: 'error' }, e);
} finally {
processing = false;
updateActionIcon();
showTransientIcon("resources/img/done.png");
} catch (e) {
processing = false;
logger.aiLog("failed to apply AI rules", { level: 'error' }, e);
showTransientIcon("resources/img/error.png");
}
});
}