init logic for basic settings
This commit is contained in:
parent
8c79c437c9
commit
8d433afa45
10
bg.js
10
bg.js
@ -1,12 +1,13 @@
|
|||||||
browser.runtime.onInstalled.addListener((ev) => {
|
browser.runtime.onInstalled.addListener((ev) => {
|
||||||
if (ev.reason == "update") {
|
if (ev.reason == "update") {
|
||||||
|
initialiseSettings();
|
||||||
updateIsSignificant(ev.previousVersion).then(
|
updateIsSignificant(ev.previousVersion).then(
|
||||||
v => {
|
v => {
|
||||||
if (v) launchInfoPage();
|
if (v) launchInfoPage();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else if (ev.reason == "install") {
|
} else if (ev.reason == "install") {
|
||||||
browser.runtime.openOptionsPage()
|
initialiseSettings().then(() => browser.runtime.openOptionsPage());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -18,3 +19,10 @@ async function updateIsSignificant(previousVersion) {
|
|||||||
function launchInfoPage(){
|
function launchInfoPage(){
|
||||||
browser.tabs.create({url: "/changelog.htm", active: false})
|
browser.tabs.create({url: "/changelog.htm", active: false})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user