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

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

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

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

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