2019-11-10 17:38:47 +00:00
|
|
|
import {browser} from 'webextension-polyfill-ts';
|
2021-02-23 15:55:40 +00:00
|
|
|
import {
|
|
|
|
defaultSettings,
|
|
|
|
getManifest,
|
|
|
|
getSettings,
|
|
|
|
setSettings,
|
|
|
|
versionAsNumber
|
|
|
|
} from '.';
|
2019-11-10 17:38:47 +00:00
|
|
|
|
|
|
|
// Add listeners to open the options page when:
|
2020-10-10 23:32:27 +00:00
|
|
|
// * The extension icon is clicked.
|
|
|
|
// * The extension is installed.
|
2019-11-10 17:38:47 +00:00
|
|
|
browser.browserAction.onClicked.addListener(openOptionsPage);
|
2021-02-23 15:55:40 +00:00
|
|
|
browser.runtime.onInstalled.addListener(async () => {
|
|
|
|
const manifest = getManifest();
|
|
|
|
const settings = await getSettings();
|
|
|
|
const versionGotUpdated =
|
|
|
|
versionAsNumber(manifest.version) >
|
|
|
|
versionAsNumber(settings.data.version ?? defaultSettings.data.version!);
|
|
|
|
|
|
|
|
if (versionGotUpdated) {
|
|
|
|
settings.data.version = manifest.version;
|
|
|
|
await setSettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (versionGotUpdated || manifest.nodeEnv === 'development') {
|
|
|
|
await openOptionsPage();
|
|
|
|
}
|
|
|
|
});
|
2019-11-10 17:38:47 +00:00
|
|
|
|
2020-10-10 23:32:27 +00:00
|
|
|
async function openOptionsPage() {
|
2019-11-10 17:38:47 +00:00
|
|
|
await browser.runtime.openOptionsPage();
|
|
|
|
}
|