aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-04 20:56:54 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-04 20:56:54 -0800
commit974b10340902faaaa88f0477cbe0fcd90ca7ee7d (patch)
treedb30df89f959245d7415233ad9c2ef4d4ab7fdf7 /ext/bg/js/util.js
parent6b6190ade7eb825720dd5cbe4485a360d6985ad2 (diff)
initial code for migration from sync storage to local storage
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 814a27f6..6d5c030c 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -188,22 +188,29 @@ function optionsVersion(options) {
}
function optionsLoad() {
- if (!chrome.storage.sync) {
- chrome.storage.sync = chrome.storage.local;
- }
-
return new Promise((resolve, reject) => {
- chrome.storage.sync.get(null, options => resolve(optionsVersion(options)));
+ if (chrome.storage.sync) {
+ chrome.storage.sync.getBytesInUse(null, resolve);
+ } else {
+ 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)));
+ });
+ }).then(options => {
+ if (chrome.storage.sync) {
+ chrome.storage.sync.clear();
+ }
+
+ return options;
});
}
function optionsSave(options) {
- if (!chrome.storage.sync) {
- chrome.storage.sync = chrome.storage.local;
- }
-
return new Promise((resolve, reject) => {
- chrome.storage.sync.set(options, resolve);
+ chrome.storage.local.set(options, resolve);
}).then(() => {
instYomi().optionsSet(options);
fgOptionsSet(options);