From: Mike Frysinger Date: Fri, 7 Oct 2022 17:32:49 +0000 (+0545) Subject: bg: check local storage directly on startup X-Git-Tag: v0.3~5 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=a18caa4dbb15ef1d7e81a2464b68651cc9526085;p=chrome-ext%2Ftabs-backup.git bg: check local storage directly on startup See if we have any backups, and if not, create one right away. This is more robust than checking localStorage.lastBackupTime directly as that isn't used anywhere else. Plus, MV3 won't support it. --- diff --git a/background.js b/background.js index 94884ec..0c90a71 100644 --- a/background.js +++ b/background.js @@ -8,8 +8,11 @@ if (!localStorage.prefsBackupTimer) { localStorage.prefsBackupTimer = "30"; } -if (!localStorage.lastBackupTime) { - localStorage.lastBackupTime = -1; +// Create a backup on first install (or if storage is wiped for some reason). +chrome.storage.local.get("backups_list", function(items) { + if (items.backups_list) { + return; + } // Create a backup now var d = new Date(); @@ -18,7 +21,7 @@ if (!localStorage.lastBackupTime) { backupNow(true, formattedDate, function(success, backupName, backupObj) { // backup completed }); -} +}); function initAlarm () { //console.log("initAlarm");