queue/source/utilities/badge.ts

24 lines
642 B
TypeScript
Raw Normal View History

2022-03-05 13:10:45 +00:00
import browser from 'webextension-polyfill';
2022-09-27 10:49:00 +00:00
import type {Settings} from '../settings/settings.js';
2022-03-05 13:10:45 +00:00
export async function updateBadge(settings: Settings): Promise<void> {
2022-03-20 18:23:59 +00:00
let action: browser.Action.Static = browser.browserAction;
if (import.meta.env.VITE_BROWSER === 'chromium') {
action = browser.action;
}
2022-03-05 13:10:45 +00:00
const queueLength = settings.queue.length.toString();
2022-03-20 18:23:59 +00:00
await action.setBadgeText({
text: queueLength === '0' ? '' : queueLength,
});
await action.setBadgeBackgroundColor({
color: '#2a2041',
2022-03-05 13:10:45 +00:00
});
2022-03-20 18:23:59 +00:00
if (import.meta.env.VITE_BROWSER === 'firefox') {
action.setBadgeTextColor({color: '#f2efff'});
}
2022-03-05 13:10:45 +00:00
}