queue/source/background-scripts/initialize.ts

32 lines
909 B
TypeScript
Raw Permalink Normal View History

2022-03-05 13:10:45 +00:00
import browser from 'webextension-polyfill';
import {Settings} from '../settings/settings.js';
import {updateBadge} from '../utilities/badge.js';
import {History} from '../utilities/history.js';
import {browserActionClicked} from './browser-action.js';
import {initializeContextMenus} from './context-menus.js';
browser.runtime.onStartup.addListener(async () => {
console.debug('Clearing history.');
await History.clear();
});
browser.browserAction.onClicked.addListener(browserActionClicked);
browser.runtime.onInstalled.addListener(async () => {
if (import.meta.env.DEV) {
await browser.runtime.openOptionsPage();
}
});
browser.runtime.onMessage.addListener(
async (request: Queue.Message<unknown>) => {
if (request.action === 'queue update badge') {
const settings = await Settings.fromSyncStorage();
await updateBadge(settings);
}
},
);
initializeContextMenus();