From 8d433afa451d3484ba2c05194510993569643ad4 Mon Sep 17 00:00:00 2001 From: iw0 Date: Wed, 29 May 2024 13:52:45 +0200 Subject: [PATCH] init logic for basic settings --- bg.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bg.js b/bg.js index 4a82545..61ae8ed 100644 --- a/bg.js +++ b/bg.js @@ -1,12 +1,13 @@ browser.runtime.onInstalled.addListener((ev) => { if (ev.reason == "update") { + initialiseSettings(); updateIsSignificant(ev.previousVersion).then( v => { if (v) launchInfoPage(); } ) } else if (ev.reason == "install") { - browser.runtime.openOptionsPage() + initialiseSettings().then(() => browser.runtime.openOptionsPage()); } }) @@ -17,4 +18,11 @@ async function updateIsSignificant(previousVersion) { } function launchInfoPage(){ browser.tabs.create({url: "/changelog.htm", active: false}) -} \ No newline at end of file +} + +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); +} \ No newline at end of file