aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/AddonEnabledUseCase.js
blob: bb2c347f8847ed171b72aa80d4231c1b9eb93963 (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
import IndicatorPresenter from '../presenters/IndicatorPresenter';
import TabPresenter from '../presenters/TabPresenter';
import ContentMessageClient from '../infrastructures/ContentMessageClient';

export default class AddonEnabledUseCase {
  constructor() {
    this.indicatorPresentor = new IndicatorPresenter();

    this.indicatorPresentor.onClick(tab => this.onIndicatorClick(tab.id));

    this.tabPresenter = new TabPresenter();
    this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId));

    this.contentMessageClient = new ContentMessageClient();
  }

  indicate(enabled) {
    return this.indicatorPresentor.indicate(enabled);
  }

  onIndicatorClick(tabId) {
    return this.contentMessageClient.toggleAddonEnabled(tabId);
  }

  async onTabSelected(tabId) {
    let enabled = await this.contentMessageClient.getAddonEnabled(tabId);
    return this.indicatorPresentor.indicate(enabled);
  }
}