Move badge update code.
This commit is contained in:
parent
861c340ec7
commit
451ebb8189
|
@ -161,3 +161,21 @@ export async function nextItem(): Promise<Value<Item> | undefined> {
|
|||
serialize: serializeItem,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the WebExtension's badge text to show the current {@link Item} count.
|
||||
*/
|
||||
export async function setBadgeText(): Promise<void> {
|
||||
const keys = await getItemKeys();
|
||||
const count = keys.length;
|
||||
const action: browser.Action.Static =
|
||||
$browser === "firefox" ? browser.browserAction : browser.action;
|
||||
|
||||
await action.setBadgeBackgroundColor({color: "#2a2041"});
|
||||
await action.setBadgeText({text: count === 0 ? "" : count.toString()});
|
||||
|
||||
// Only Firefox supports the `setBadgeTextColor` function.
|
||||
if ($browser === "firefox") {
|
||||
action.setBadgeTextColor({color: "#f2efff"});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import browser from 'webextension-polyfill';
|
||||
|
||||
import type {Settings} from '../settings/settings.js';
|
||||
|
||||
export async function updateBadge(settings: Settings): Promise<void> {
|
||||
let action: browser.Action.Static = browser.browserAction;
|
||||
if (import.meta.env.VITE_BROWSER === 'chromium') {
|
||||
action = browser.action;
|
||||
}
|
||||
|
||||
const queueLength = settings.queue.length.toString();
|
||||
await action.setBadgeText({
|
||||
text: queueLength === '0' ? '' : queueLength,
|
||||
});
|
||||
|
||||
await action.setBadgeBackgroundColor({
|
||||
color: '#2a2041',
|
||||
});
|
||||
|
||||
if (import.meta.env.VITE_BROWSER === 'firefox') {
|
||||
action.setBadgeTextColor({color: '#f2efff'});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue