blob: fa158a3dcd944ac90c00216c66d5619b99918cbf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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(({ settings }) => {
if (!settings) {
return set(DefaultSettings);
}
return set(Object.assign({}, DefaultSettings, settings));
}, console.error);
};
const save = (settings) => {
return browser.storage.local.set({
settings,
}).then(() => {
return browser.runtime.sendMessage({
type: messages.SETTINGS_RELOAD
}).then(() => {
return set(settings);
});
});
};
const set = (settings) => {
return {
type: actions.SETTING_SET_SETTINGS,
source: settings.source,
json: settings.json,
form: settings.form,
value: JSON.parse(settings.json),
};
};
export { load, save };
|