From 44c1df67c4f0984c04965569fdedbbd086c9798c Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 28 Feb 2015 00:38:22 -0500 Subject: [PATCH] Move createOptionsStorage to background.js --- background.js | 25 ++++++++++++++++++++++--- options.js | 20 ++------------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/background.js b/background.js index 8179e60..9c0797f 100644 --- a/background.js +++ b/background.js @@ -4,6 +4,16 @@ function createWindowStorage(callback){ chrome.storage.local.set({'windows':[]},callback); } +function createOptionsStorage(callback){ + chrome.storage.local.set({"options":{ + 'darkMode':true, + }}); +} + +function getOptions(callback){ + chrome.storage.local.get("options",callback); +} + function populateWindowStorage(callback){ chrome.windows.getAll({'populate':true},function(result){ result = result.filter(function(currentWindow){ @@ -185,9 +195,18 @@ chrome.storage.local.get('windows',function(result){ console.log(result); }); - clearWindowStorage(function(){ - createWindowStorage(function(){ - populateWindowStorage(); + getOptions(function(data){ + if (Object.keys(data).length===0){ + createOptionsStorage(function(){ + getOptions(function(data){ + options = data.options; + setupOptionsView(optionsDiv); + }); + }); + } + createWindowStorage(function(){ + populateWindowStorage(); + }); }); }); diff --git a/options.js b/options.js index f45f497..503a861 100644 --- a/options.js +++ b/options.js @@ -1,11 +1,5 @@ var options; -function createOptionsStorage(callback){ - chrome.storage.local.set({"options":{ - 'darkMode':true, - }}); -} - function getOptions(callback){ chrome.storage.local.get("options",callback); } @@ -28,17 +22,7 @@ function setupOptionsView(optionsDiv){ document.addEventListener('DOMContentLoaded', function(event){ var optionsDiv = document.getElementById("options"); getOptions(function(data){ - if (Object.keys(data).length===0){ - createOptionsStorage(function(){ - getOptions(function(data){ - options = data.options; - setupOptionsView(optionsDiv); - }); - }); - } - else{ - options = data.options; - setupOptionsView(optionsDiv); - } + options = data.options; + setupOptionsView(optionsDiv); }); }); \ No newline at end of file