From 29c731224ec5ba0509473159fec48fa4a2c28b8c Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 7 Mar 2015 15:16:07 -0500 Subject: [PATCH] Fix bug where sync options wouldn't be read --- background.js | 15 ++++++++++++--- options.js | 1 - popup.js | 9 ++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index 1ca20e2..ee8ba84 100644 --- a/background.js +++ b/background.js @@ -5,14 +5,23 @@ function createWindowStorage(callback){ } function createOptionsStorage(callback){ - chrome.storage.local.set({"options":{ + var defaultSettings = {"options":{ 'darkMode':true, 'sync':true, - }}); + }}; + chrome.storage.local.set(defaultSettings); + chrome.storage.sync.set(defaultSettings); } function getOptions(callback){ - chrome.storage.local.get("options",callback); + chrome.storage.local.get("options",function(items){ + if (items.sync){ + chrome.storage.sync.get("options",callback); + } + else{ + callback(items); + } + }); } function populateWindowStorage(callback){ diff --git a/options.js b/options.js index f2a69fd..11f093e 100644 --- a/options.js +++ b/options.js @@ -13,7 +13,6 @@ function getOptions(callback){ function saveOptions(callback){ chrome.storage.local.set({"options":options},function(){ - console.log(options); if (options.sync){ chrome.storage.sync.set({"options":options},callback); } diff --git a/popup.js b/popup.js index 3aae40e..fa8e514 100644 --- a/popup.js +++ b/popup.js @@ -8,7 +8,14 @@ function getStorage(callback){ } function getOptions(callback){ - chrome.storage.local.get("options",callback); + chrome.storage.local.get("options",function(items){ + if (items.sync){ + chrome.storage.sync.get("options",callback); + } + else{ + callback(items); + } + }); } function changeWindowName(windowId,newName,callback){