summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 6d5c030c..75847ee6 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -195,10 +195,24 @@ function optionsLoad() {
resolve(0);
}
}).then(bytes => {
- const storage = bytes === 0 ? chrome.storage.local : chrome.storage.sync;
- return new Promise((resolve, reject) => {
- storage.get(null, options => resolve(optionsVersion(options)));
- });
+ if (bytes === 0) {
+ 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));
+ });
+ });
+ } else {
+ return new Promise((resolve, reject) => {
+ chrome.storage.sync.get(null, options => resolve(optionsVersion(options)));
+ });
+ }
}).then(options => {
if (chrome.storage.sync) {
chrome.storage.sync.clear();
@@ -210,7 +224,7 @@ function optionsLoad() {
function optionsSave(options) {
return new Promise((resolve, reject) => {
- chrome.storage.local.set(options, resolve);
+ chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
}).then(() => {
instYomi().optionsSet(options);
fgOptionsSet(options);