aboutsummaryrefslogtreecommitdiff
path: root/src/content/client/OperationClient.ts
blob: 2bc7aee80c473b80b36f7d1baa4b8374331a551e (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
39
import * as operations from "../../shared/operations";
import * as messages from "../../shared/messages";

export default interface OperationClient {
  execBackgroundOp(repeat: number, op: operations.Operation): Promise<void>;

  internalOpenUrl(
    url: string,
    newTab?: boolean,
    background?: boolean
  ): Promise<void>;
}

export class OperationClientImpl implements OperationClient {
  execBackgroundOp(repeat: number, op: operations.Operation): Promise<void> {
    return browser.runtime.sendMessage({
      type: messages.BACKGROUND_OPERATION,
      repeat,
      operation: op,
    });
  }

  internalOpenUrl(
    url: string,
    newTab?: boolean,
    background?: boolean
  ): Promise<void> {
    return browser.runtime.sendMessage({
      type: messages.BACKGROUND_OPERATION,
      repeat: 1,
      operation: {
        type: operations.INTERNAL_OPEN_URL,
        url,
        newTab,
        background,
      },
    });
  }
}