diff options
Diffstat (limited to 'src/background/clients')
-rw-r--r-- | src/background/clients/FindClient.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/background/clients/FindClient.ts b/src/background/clients/FindClient.ts new file mode 100644 index 0000000..b46b964 --- /dev/null +++ b/src/background/clients/FindClient.ts @@ -0,0 +1,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 } + ); + } +} |