aboutsummaryrefslogtreecommitdiff
path: root/src/background/Application.ts
blob: 08013cd1f4ba647263c7c2abe568aaf8f10dda55 (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
import { injectable } from 'tsyringe';
import ContentMessageListener from './infrastructures/ContentMessageListener';
import SettingController from './controllers/SettingController';
import VersionController from './controllers/VersionController';

@injectable()
export default class Application {
  constructor(
    private contentMessageListener: ContentMessageListener,
    private settingController: SettingController,
    private versionController: VersionController,
  ) {
  }

  run() {
    this.settingController.reload();

    browser.runtime.onInstalled.addListener((details) => {
      if (details.reason !== 'install' && details.reason !== 'update') {
        return;
      }
      this.versionController.notify();
    });

    this.contentMessageListener.run();
    browser.storage.onChanged.addListener((changes, area) => {
      if (area !== 'local') {
        return;
      }
      if (changes.settings) {
        this.settingController.reload();
      }
    });
  }
}