aboutsummaryrefslogtreecommitdiff
path: root/src/content/operators/impls/ToggleAddonOperator.ts
blob: 1019b8b224468e88a78d9ff48d9f36b7b4b3dc37 (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
import Operator from "../Operator";
import AddonIndicatorClient from "../../client/AddonIndicatorClient";
import AddonEnabledRepository from "../../repositories/AddonEnabledRepository";
import ConsoleFramePresenter from "../../presenters/ConsoleFramePresenter";

export default class ToggleAddonOperator implements Operator {
  constructor(
    private readonly indicator: AddonIndicatorClient,
    private readonly repository: AddonEnabledRepository,
    private readonly consoleFramePresenter: ConsoleFramePresenter
  ) {}

  async run(): Promise<void> {
    const enabled = !this.repository.get();
    this.repository.set(enabled);
    if (enabled) {
      this.consoleFramePresenter.attach();
    } else {
      this.consoleFramePresenter.detach();
    }
    await this.indicator.setEnabled(enabled);
  }
}