queue/source/background-scripts/initialize.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-05 13:10:45 +00:00
import browser from 'webextension-polyfill';
2022-03-16 10:20:29 +00:00
import {Settings} from '../settings/settings.js';
import {updateBadge} from '../utilities/badge.js';
2022-03-05 13:10:45 +00:00
import {History} from '../utilities/history.js';
import {actionClicked, browserActionClicked} from './browser-action.js';
import {
contextClicked,
getContextMenus,
initializeContextMenus,
} from './context-menus.js';
2022-03-05 13:10:45 +00:00
browser.runtime.onStartup.addListener(async () => {
console.debug('Clearing history.');
await History.clear();
2022-03-16 10:20:29 +00:00
await updateBadge(await Settings.fromSyncStorage());
2022-03-05 13:10:45 +00:00
});
if (import.meta.env.VITE_BROWSER === 'chromium') {
browser.action.onClicked.addListener(actionClicked);
} else {
browser.browserAction.onClicked.addListener(browserActionClicked);
}
2022-03-05 13:10:45 +00:00
browser.runtime.onInstalled.addListener(async () => {
await initializeContextMenus();
await updateBadge(await Settings.fromSyncStorage());
2022-03-05 13:10:45 +00:00
});
if (import.meta.env.DEV) {
void browser.runtime.openOptionsPage();
}
browser.contextMenus.onClicked.addListener(async (info, tab) => {
const contextMenus = getContextMenus();
const contextMenuIds = new Set<string>(
contextMenus.map(({id}) => id ?? 'queue-unknown'),
);
await contextClicked(contextMenuIds, info, tab);
});