queue/source/background/setup.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-04-27 10:47:19 +00:00
// The main entry point for the background script. Note that in Manifest V3 this
// is run in a service worker.
// https://developer.chrome.com/docs/extensions/migrating/to-service-workers/
import browser from "webextension-polyfill";
import {runMigrations} from "../migrations/migrations.js";
2023-04-27 10:47:19 +00:00
import {
clearHistory,
openNextItemOrOptionsPage,
setBadgeText,
} from "../item/item.js";
import {firefoxActionClick} from "./action.js";
import {
contextClicked,
getContextMenus,
initializeContextMenus,
} from "./context-menu.js";
if ($browser === "firefox") {
browser.browserAction.onClicked.addListener(firefoxActionClick);
} else {
browser.action.onClicked.addListener(async () => {
await openNextItemOrOptionsPage();
});
}
browser.runtime.onStartup.addListener(async () => {
await clearHistory();
await setBadgeText();
});
browser.runtime.onInstalled.addListener(async () => {
await runMigrations();
2023-04-27 10:47:19 +00:00
await initializeContextMenus();
await setBadgeText();
if ($dev) {
await browser.runtime.openOptionsPage();
}
});
browser.contextMenus.onClicked.addListener(async (info, tab) => {
const contextMenus = getContextMenus();
const contextMenuIds = new Set<string>(contextMenus.map(({id}) => id!));
await contextClicked(contextMenuIds, info, tab);
});