1
Fork 0
tildes-reextended/source/background/setup.ts

28 lines
885 B
TypeScript
Raw Permalink Normal View History

2023-06-23 10:52:03 +00:00
import browser from "webextension-polyfill";
import {migrations} from "../storage/migrations/migrations.js";
import {log} from "../utilities/logging.js";
2023-06-23 10:52:03 +00:00
if ($browser === "firefox") {
browser.browserAction.onClicked.addListener(openOptionsPage);
} else if ($browser === "chromium") {
browser.action.onClicked.addListener(openOptionsPage);
}
browser.runtime.onInstalled.addListener(async () => {
const existingStorage = await browser.storage.sync.get();
if (existingStorage.version === "1.1.2") {
log("Running 1.1.2 to 2.0.0 data migration.", true);
await browser.storage.local.set({backup: JSON.stringify(existingStorage)});
await browser.storage.sync.clear();
await migrations[0].migrate(existingStorage);
}
2023-06-23 10:52:03 +00:00
if ($dev) {
await openOptionsPage();
}
});
async function openOptionsPage(): Promise<void> {
await browser.runtime.openOptionsPage();
}