diff --git a/source/item/item.ts b/source/item/item.ts index f53faff..7e3090f 100644 --- a/source/item/item.ts +++ b/source/item/item.ts @@ -161,3 +161,21 @@ export async function nextItem(): Promise | undefined> { serialize: serializeItem, }); } + +/** + * Set the WebExtension's badge text to show the current {@link Item} count. + */ +export async function setBadgeText(): Promise { + 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"}); + } +} diff --git a/source/utilities/badge.ts b/source/utilities/badge.ts deleted file mode 100644 index 00a4b86..0000000 --- a/source/utilities/badge.ts +++ /dev/null @@ -1,23 +0,0 @@ -import browser from 'webextension-polyfill'; - -import type {Settings} from '../settings/settings.js'; - -export async function updateBadge(settings: Settings): Promise { - 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'}); - } -}