|
|
@ -1,30 +1,28 @@ |
|
|
|
import DefaultSettings from './default'; |
|
|
|
import DefaultSettings from './default'; |
|
|
|
import * as settingsValues from './values'; |
|
|
|
import * as settingsValues from './values'; |
|
|
|
|
|
|
|
|
|
|
|
const loadRaw = () => { |
|
|
|
const loadRaw = async() => { |
|
|
|
return browser.storage.local.get('settings').then(({ settings }) => { |
|
|
|
let { settings } = await browser.storage.local.get('settings'); |
|
|
|
if (!settings) { |
|
|
|
if (!settings) { |
|
|
|
return DefaultSettings; |
|
|
|
return DefaultSettings; |
|
|
|
} |
|
|
|
} |
|
|
|
return Object.assign({}, DefaultSettings, settings); |
|
|
|
return Object.assign({}, DefaultSettings, settings); |
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const loadValue = () => { |
|
|
|
const loadValue = async() => { |
|
|
|
return loadRaw().then((settings) => { |
|
|
|
let settings = await loadRaw(); |
|
|
|
let value = JSON.parse(DefaultSettings.json); |
|
|
|
let value = JSON.parse(DefaultSettings.json); |
|
|
|
if (settings.source === 'json') { |
|
|
|
if (settings.source === 'json') { |
|
|
|
value = settingsValues.valueFromJson(settings.json); |
|
|
|
value = settingsValues.valueFromJson(settings.json); |
|
|
|
} else if (settings.source === 'form') { |
|
|
|
} else if (settings.source === 'form') { |
|
|
|
value = settingsValues.valueFromForm(settings.form); |
|
|
|
value = settingsValues.valueFromForm(settings.form); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!value.properties) { |
|
|
|
if (!value.properties) { |
|
|
|
value.properties = {}; |
|
|
|
value.properties = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
return Object.assign({}, |
|
|
|
return Object.assign({}, |
|
|
|
settingsValues.valueFromJson(DefaultSettings.json), |
|
|
|
settingsValues.valueFromJson(DefaultSettings.json), |
|
|
|
value); |
|
|
|
value); |
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const save = (settings) => { |
|
|
|
const save = (settings) => { |
|
|
|