aboutsummaryrefslogtreecommitdiff
path: root/src/settings/storage.ts
blob: 2a983dfaa5ea676e6c09ac65c039b72202396fa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import SettingData, { DefaultSettingData } from '../shared/SettingData';

export const load = async(): Promise<SettingData> => {
  let { settings } = await browser.storage.local.get('settings');
  if (!settings) {
    return DefaultSettingData;
  }
  try {
    return SettingData.fromJSON(settings as any);
  } catch (e) {
    console.error('unable to load settings', e);
    return DefaultSettingData;
  }
};

export const save = (data: SettingData) => {
  return browser.storage.local.set({
    settings: data.toJSON(),
  });
};