bc100-autofill/bg.js

28 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-05-01 15:35:24 +02:00
browser.runtime.onInstalled.addListener((ev) => {
if (ev.reason == "update") {
2024-05-29 13:52:45 +02:00
initialiseSettings();
2024-05-03 23:23:33 +02:00
updateIsSignificant(ev.previousVersion).then(
v => {
if (v) launchInfoPage();
}
)
2024-05-01 15:35:24 +02:00
} else if (ev.reason == "install") {
2024-05-29 13:52:45 +02:00
initialiseSettings().then(() => browser.runtime.openOptionsPage());
2024-05-01 15:35:24 +02:00
}
})
async function updateIsSignificant(previousVersion) {
const significantUpdates = ["0.1.0", "0.2.0", "0.3.0"];
let currentVersion = (await browser.management.getSelf()).version;
2024-05-29 13:54:06 +02:00
return (currentVersion in significantUpdates) || currentVersion.endsWith('.0'); // semver! :D
2024-05-01 15:35:24 +02:00
}
function launchInfoPage(){
browser.tabs.create({url: "/changelog.htm", active: false})
2024-05-29 13:52:45 +02:00
}
async function initialiseSettings(){
let defaultSettings = {"enable": true, "showChangelog": true};
const presentSettings = await browser.storage.sync.get();
defaultSettings = Object.fromEntries(Object.entries(defaultSettings).filter((k, v) => !(k in presentSettings)));
await browser.storage.sync.set(defaultSettings);
}