blob: 90a3a66bf46a0d2032846fe5cca66c1c67833ed5 (
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
|
import DefaultSettings from './default';
import * as settingsValues from './values';
const loadRaw = async(): Promise<any> => {
let { settings } = await browser.storage.local.get('settings');
if (!settings) {
return DefaultSettings;
}
return { ...DefaultSettings, ...settings as object };
};
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: any): Promise<any> => {
return browser.storage.local.set({
settings,
});
};
export { loadRaw, loadValue, save };
|