diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/settings/storage.js | 40 | ||||
-rw-r--r-- | src/shared/settings/values.js | 6 | ||||
-rw-r--r-- | src/shared/versions/index.js | 13 | ||||
-rw-r--r-- | src/shared/versions/storage.js | 7 |
4 files changed, 30 insertions, 36 deletions
diff --git a/src/shared/settings/storage.js b/src/shared/settings/storage.js index 9b8045d..5dce3b0 100644 --- a/src/shared/settings/storage.js +++ b/src/shared/settings/storage.js @@ -1,30 +1,26 @@ import DefaultSettings from './default'; import * as settingsValues from './values'; -const loadRaw = () => { - return browser.storage.local.get('settings').then(({ settings }) => { - if (!settings) { - return DefaultSettings; - } - return Object.assign({}, DefaultSettings, settings); - }); +const loadRaw = async() => { + let { settings } = await browser.storage.local.get('settings'); + if (!settings) { + return DefaultSettings; + } + return { ...DefaultSettings, ...settings }; }; -const loadValue = () => { - return loadRaw().then((settings) => { - let value = JSON.parse(DefaultSettings.json); - if (settings.source === 'json') { - value = settingsValues.valueFromJson(settings.json); - } else if (settings.source === 'form') { - value = settingsValues.valueFromForm(settings.form); - } - if (!value.properties) { - value.properties = {}; - } - return Object.assign({}, - settingsValues.valueFromJson(DefaultSettings.json), - value); - }); +const loadValue = async() => { + let settings = await loadRaw(); + let value = JSON.parse(DefaultSettings.json); + if (settings.source === 'json') { + value = settingsValues.valueFromJson(settings.json); + } else if (settings.source === 'form') { + value = settingsValues.valueFromForm(settings.form); + } + if (!value.properties) { + value.properties = {}; + } + return { ...settingsValues.valueFromJson(DefaultSettings.json), ...value }; }; const save = (settings) => { diff --git a/src/shared/settings/values.js b/src/shared/settings/values.js index bd03be2..9828af6 100644 --- a/src/shared/settings/values.js +++ b/src/shared/settings/values.js @@ -6,12 +6,12 @@ const operationFromFormName = (name) => { if (argStr) { args = JSON.parse(argStr); } - return Object.assign({ type }, args); + return { type, ...args }; }; const operationToFormName = (op) => { let type = op.type; - let args = Object.assign({}, op); + let args = { ...op }; delete args.type; if (Object.keys(args).length === 0) { @@ -83,7 +83,7 @@ const formFromValue = (value, allowedOps) => { } } - let formProperties = Object.assign({}, properties.defaults, value.properties); + let formProperties = { ...properties.defaults, ...value.properties }; return { keymaps, diff --git a/src/shared/versions/index.js b/src/shared/versions/index.js index ee9f3b5..ba3d183 100644 --- a/src/shared/versions/index.js +++ b/src/shared/versions/index.js @@ -13,13 +13,12 @@ const notificationClickListener = (id) => { browser.notifications.onClicked.removeListener(notificationClickListener); }; -const checkUpdated = () => { - return storage.load().then((prev) => { - if (!prev) { - return true; - } - return manifest.version !== prev; - }); +const checkUpdated = async() => { + let prev = await storage.load(); + if (!prev) { + return true; + } + return manifest.version !== prev; }; const notify = () => { diff --git a/src/shared/versions/storage.js b/src/shared/versions/storage.js index 37603c8..7883258 100644 --- a/src/shared/versions/storage.js +++ b/src/shared/versions/storage.js @@ -1,7 +1,6 @@ -const load = () => { - return browser.storage.local.get('version').then(({ version }) => { - return version; - }); +const load = async() => { + let { version } = await browser.storage.local.get('version'); + return version; }; const save = (version) => { |