aboutsummaryrefslogtreecommitdiff
path: root/src/background/clients/FindClient.ts
blob: b46b9647f7b238c416eb940659c612adf16ee36c (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
40
41
42
43
44
45
import * as messages from "../../shared/messages";

export default interface FindClient {
  findNext(tabId: number, frameId: number, keyword: string): Promise<boolean>;

  findPrev(tabId: number, frameId: number, keyword: string): Promise<boolean>;

  clearSelection(tabId: number, frameId: number): Promise<void>;
}

export class FindClientImpl implements FindClient {
  async findNext(
    tabId: number,
    frameId: number,
    keyword: string
  ): Promise<boolean> {
    const found = (await browser.tabs.sendMessage(
      tabId,
      { type: messages.FIND_NEXT, keyword },
      { frameId }
    )) as boolean;
    return found;
  }

  async findPrev(
    tabId: number,
    frameId: number,
    keyword: string
  ): Promise<boolean> {
    const found = (await browser.tabs.sendMessage(
      tabId,
      { type: messages.FIND_PREV, keyword },
      { frameId }
    )) as boolean;
    return found;
  }

  clearSelection(tabId: number, frameId: number): Promise<void> {
    return browser.tabs.sendMessage(
      tabId,
      { type: messages.FIND_CLEAR_SELECTION },
      { frameId }
    );
  }
}