summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-05 11:29:28 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-05 11:29:28 -0800
commit592f15f96c3a18215859c1f0d3c24ae00e454cdd (patch)
tree6bb3f896bec2af84994519dc673b83b9e4aaf04b /ext/bg/js/util.js
parent200b8f6b7537ff14ef17e9387dbf6dd642e3d4b9 (diff)
options
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js36
1 files changed, 11 insertions, 25 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 75847ee6..a2d2d9d3 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -189,36 +189,22 @@ function optionsVersion(options) {
function optionsLoad() {
return new Promise((resolve, reject) => {
- if (chrome.storage.sync) {
- chrome.storage.sync.getBytesInUse(null, resolve);
- } else {
- resolve(0);
- }
- }).then(bytes => {
- if (bytes === 0) {
+ chrome.storage.local.get(null, store => resolve(store.options));
+ }).then(optionsStr => {
+ if (optionsStr) {
+ return JSON.parse(optionsStr);
+ } else if (chrome.storage.sync) {
return new Promise((resolve, reject) => {
- chrome.storage.local.get(null, store => {
- let options = {};
- try {
- options = JSON.parse(store.options);
- } catch (e) {
- // NOP
- }
-
- resolve(optionsVersion(options));
- });
+ chrome.storage.sync.get(null, options => resolve(options));
});
} else {
- return new Promise((resolve, reject) => {
- chrome.storage.sync.get(null, options => resolve(optionsVersion(options)));
- });
+ return {};
}
+ }).catch(error => {
+ console.log(error);
+ return {};
}).then(options => {
- if (chrome.storage.sync) {
- chrome.storage.sync.clear();
- }
-
- return options;
+ return optionsVersion(options);
});
}