aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions/setting.ts
blob: 92f85590d829cc18f8b2928df1456d9e42f94014 (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
import * as actions from './index';
import * as operations from '../../shared/operations';
import * as messages from '../../shared/messages';
import Settings, { Keymaps } from '../../shared/Settings';

const reservedKeymaps: Keymaps = {
  '<Esc>': { type: operations.CANCEL },
  '<C-[>': { type: operations.CANCEL },
};

const set = (settings: Settings): actions.SettingAction => {
  return {
    type: actions.SETTING_SET,
    settings: {
      ...settings,
      keymaps: { ...settings.keymaps, ...reservedKeymaps },
    }
  };
};

const load = async(): Promise<actions.SettingAction> => {
  let settings = await browser.runtime.sendMessage({
    type: messages.SETTINGS_QUERY,
  });
  return set(settings);
};

export { set, load };