From 8f81b69501b78e1379ba774825e2d0d0530bce32 Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 30 Aug 2017 13:38:42 -0700 Subject: [PATCH] Fix a race condition between the setting of the storage object and retrieval of background.js globals from that object --- chromium/background.js | 23 +++++++++++++---------- chromium/storage.js | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/chromium/background.js b/chromium/background.js index 79bf1274df81..c336622f8d26 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -67,16 +67,19 @@ var httpNowhereOn = false; var showCounter = true; var isExtensionEnabled = true; -storage.get({ - httpNowhere: false, - showCounter: true, - globalEnabled: true -}, function(item) { - httpNowhereOn = item.httpNowhere; - showCounter = item.showCounter; - isExtensionEnabled = item.globalEnabled; - updateState(); -}); +var initializeStoredGlobals = () => { + storage.get({ + httpNowhere: false, + showCounter: true, + globalEnabled: true + }, function(item) { + httpNowhereOn = item.httpNowhere; + showCounter = item.showCounter; + isExtensionEnabled = item.globalEnabled; + updateState(); + }); +} +initializeStoredGlobals(); chrome.storage.onChanged.addListener(function(changes, areaName) { if (areaName === 'sync' || areaName === 'local') { diff --git a/chromium/storage.js b/chromium/storage.js index d75fe7794411..0fed52997fcb 100644 --- a/chromium/storage.js +++ b/chromium/storage.js @@ -3,6 +3,7 @@ if (chrome.storage.sync) { chrome.storage.sync.set({"sync-set-test": true}, () => { if(!chrome.runtime.lastError){ storage = chrome.storage.sync; + initializeStoredGlobals(); } }); }