aboutsummaryrefslogtreecommitdiff
path: root/src/settings/actions/setting.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 13:51:07 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 13:51:07 +0900
commit4d7c24f38a6861e1d498b6e7dd5c7be2d1a0ad15 (patch)
tree0948f730a25eeda127c56a0f01009f14d066e4dc /src/settings/actions/setting.js
parent177940981ed9c4f096ad7db20f0b7ee044fd7b17 (diff)
parentfb8a0f36aa4d070df936cc7598ef8dd988ee1b15 (diff)
Merge remote-tracking branch 'origin/master' into background-adjacent-tabs
Diffstat (limited to 'src/settings/actions/setting.js')
-rw-r--r--src/settings/actions/setting.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/settings/actions/setting.js b/src/settings/actions/setting.js
index c1b27c8..92c9f8a 100644
--- a/src/settings/actions/setting.js
+++ b/src/settings/actions/setting.js
@@ -1,34 +1,39 @@
import actions from 'settings/actions';
import messages from 'shared/messages';
-import DefaultSettings from 'shared/default-settings';
+import DefaultSettings from 'shared/settings/default';
+import * as settingsStorage from 'shared/settings/storage';
+import * as settingsValues from 'shared/settings/values';
const load = () => {
- return browser.storage.local.get('settings').then(({ settings }) => {
- if (settings) {
- return set(settings);
- }
- return set(DefaultSettings);
- }, console.error);
+ return settingsStorage.loadRaw().then((settings) => {
+ return set(settings);
+ });
};
const save = (settings) => {
- return browser.storage.local.set({
- settings,
- }).then(() => {
+ return settingsStorage.save(settings).then(() => {
return browser.runtime.sendMessage({
type: messages.SETTINGS_RELOAD
- }).then(() => {
- return set(settings);
});
+ }).then(() => {
+ return set(settings);
});
};
const set = (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);
+ }
+
return {
type: actions.SETTING_SET_SETTINGS,
source: settings.source,
json: settings.json,
- value: JSON.parse(settings.json),
+ form: settings.form,
+ value,
};
};