Index: lib/prefs.js |
=================================================================== |
--- a/lib/prefs.js |
+++ b/lib/prefs.js |
@@ -261,7 +261,7 @@ |
function savePref(pref) |
{ |
- ext.storage.set(prefToKey(pref), overrides[pref]); |
+ browser.storage.local.set({[prefToKey(pref)]: overrides[pref]}); |
} |
let customSave = new Map(); |
@@ -310,7 +310,7 @@ |
if (value == defaultValue) |
{ |
delete overrides[pref]; |
- ext.storage.remove(prefToKey(pref)); |
+ browser.storage.local.remove(prefToKey(pref)); |
} |
else |
{ |
@@ -327,44 +327,41 @@ |
let prefs = Object.keys(defaults); |
prefs.forEach(addPreference); |
- let localLoaded = new Promise(resolve => |
- { |
- ext.storage.get(prefs.map(prefToKey), items => |
+ let localLoaded = browser.storage.local.get(prefs.map(prefToKey)).then( |
+ items => |
{ |
for (let key in items) |
overrides[keyToPref(key)] = items[key]; |
+ }, |
+ (error) => |
kzar
2018/04/24 20:38:56
Nit: Superfluous parenthesis, also could we just p
Sebastian Noack
2018/04/24 21:12:55
Acknowledged.
kzar
2018/04/25 10:33:39
Ah right, well it's not a big deal then.
|
+ { |
+ console.error(error); |
+ } |
+ ); |
- resolve(); |
- }); |
- }); |
- |
- let managedLoaded = new Promise(resolve => |
+ let managedLoaded; |
+ if ("managed" in browser.storage) |
{ |
- if ("managed" in browser.storage) |
- { |
- browser.storage.managed.get(null, items => |
+ managedLoaded = browser.storage.managed.get(null).then( |
+ items => |
{ |
- // Opera doesn't support browser.storage.managed, but instead simply |
- // removing the API, Opera sets browser.runtime.lastError when using it. |
- // So we have to retrieve that error, to prevent it from showing up |
- // in the console. |
- browser.runtime.lastError; |
- |
for (let key in items) |
defaults[key] = items[key]; |
+ }, |
- resolve(); |
- }); |
- } |
- else |
- { |
- resolve(); |
- } |
- }); |
+ // Opera doesn't support browser.storage.managed, but instead of simply |
+ // removing the API, it gives an asynchronous error which we ignore here. |
+ () => {} |
+ ); |
+ } |
+ else |
+ { |
+ managedLoaded = Promise.resolve(); |
+ } |
function onLoaded() |
{ |
- ext.storage.onChanged.addListener(changes => |
+ browser.storage.onChanged.addListener(changes => |
{ |
for (let key in changes) |
{ |