aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/LinkUseCase.ts
blob: 7fa3d9c453d163aca61580ba416022eb5c274df4 (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
import { inject, injectable } from "tsyringe";
import TabPresenter from "../presenters/TabPresenter";

@injectable()
export default class LinkUseCase {
  constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {}

  async openToTab(url: string, tabId: number): Promise<void> {
    await this.tabPresenter.open(url, tabId);
  }

  async openNewTab(
    url: string,
    openerId: number,
    background: boolean
  ): Promise<void> {
    const properties: any = { active: !background };

    const platform = await browser.runtime.getPlatformInfo();
    if (platform.os !== "android") {
      // openerTabId not supported on Android
      properties.openerTabId = openerId;
    }

    await this.tabPresenter.create(url, properties);
  }
}