aboutsummaryrefslogtreecommitdiff
path: root/src/settings/storage.ts
blob: f375e586759e569e6dce2350a56f232ada87e197 (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> => {
  const { 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(),
  });
};