diff options
Diffstat (limited to 'src/settings/actions')
-rw-r--r-- | src/settings/actions/index.js | 4 | ||||
-rw-r--r-- | src/settings/actions/setting.js | 31 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/settings/actions/index.js b/src/settings/actions/index.js new file mode 100644 index 0000000..8c212c2 --- /dev/null +++ b/src/settings/actions/index.js @@ -0,0 +1,4 @@ +export default { + // Settings + SETTING_SET_SETTINGS: 'setting.set.settings', +}; diff --git a/src/settings/actions/setting.js b/src/settings/actions/setting.js new file mode 100644 index 0000000..697bcf0 --- /dev/null +++ b/src/settings/actions/setting.js @@ -0,0 +1,31 @@ +import actions from 'settings/actions'; +import messages from 'shared/messages'; +import DefaultSettings from 'shared/default-settings'; + +const load = () => { + return browser.storage.local.get('settings').then((value) => { + if (value.settings) { + return set(value.settings); + } + return set(DefaultSettings); + }, console.error); +}; + +const save = (settings) => { + return browser.storage.local.set({ + settings + }).then(() => { + return browser.runtime.sendMessage({ + type: messages.SETTINGS_RELOAD + }); + }); +}; + +const set = (settings) => { + return { + type: actions.SETTING_SET_SETTINGS, + settings, + }; +}; + +export { load, save, set }; |