aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
blob: a2e3e3daa68767f2dbfd4ad607f2665a1821f029 (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
37
38
39
40
41
42
43
44
45
import './console-frame.scss';
import * as consoleFrames from './console-frames';
import * as settingActions from 'actions/setting';
import { createStore } from 'store';
import ContentInputComponent from 'components/content-input';
import FollowComponent from 'components/follow';
import reducers from 'reducers';
import messages from './messages';

const store = createStore(reducers);
const followComponent = new FollowComponent(window.document.body, store);
const contentInputComponent = new ContentInputComponent(window, store);
store.subscribe(() => {
  try {
    followComponent.update();
    contentInputComponent.update();
  } catch (e) {
    console.error(e);
  }
});

consoleFrames.initialize(window.document);

const reloadSettings = () => {
  return browser.runtime.sendMessage({
    type: messages.SETTINGS_QUERY,
  }).then((settings) => {
    store.dispatch(settingActions.set(settings));
  });
};

browser.runtime.onMessage.addListener((action) => {
  switch (action.type) {
  case messages.CONSOLE_HIDE:
    window.focus();
    consoleFrames.blur(window.document);
    return Promise.resolve();
  case messages.SETTINGS_CHANGED:
    return reloadSettings();
  default:
    return Promise.resolve();
  }
});

reloadSettings();