Move createOptionsStorage to background.js

This commit is contained in:
Nick Krichevsky 2015-02-28 00:38:22 -05:00
parent dca2298ccd
commit 44c1df67c4
2 changed files with 24 additions and 21 deletions

View file

@ -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();
});
});
});

View file

@ -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);
});
});