aboutsummaryrefslogtreecommitdiff
path: root/src/background/operators/impls/InternalOperatorFactoryChain.ts
blob: 05615f67a47035429e1490b51af8386d39873b94 (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
import { inject, injectable } from "tsyringe";
import Operator from "../Operator";
import OperatorFactoryChain from "../OperatorFactoryChain";
import CancelOperator from "./CancelOperator";
import InternalOpenURLOperator from "./InternalOpenURLOperator";
import TabPresenter from "../../presenters/TabPresenter";
import ConsoleClient from "../../infrastructures/ConsoleClient";
import WindowPresenter from "../../presenters/WindowPresenter";
import * as operations from "../../../shared/operations";

@injectable()
export default class InternalOperatorFactoryChain
  implements OperatorFactoryChain {
  constructor(
    @inject("WindowPresenter")
    private readonly windowPresenter: WindowPresenter,
    @inject("TabPresenter")
    private readonly tabPresenter: TabPresenter,
    @inject("ConsoleClient")
    private readonly consoleClient: ConsoleClient
  ) {}

  create(op: operations.Operation): Operator | null {
    switch (op.type) {
      case operations.CANCEL:
        return new CancelOperator(this.tabPresenter, this.consoleClient);
      case operations.INTERNAL_OPEN_URL:
        return new InternalOpenURLOperator(
          this.windowPresenter,
          this.tabPresenter,
          op.url,
          op.newTab,
          op.newWindow
        );
    }
    return null;
  }
}