aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures/ConsoleClient.ts
blob: 2a1df5b9c8835a75404e19566c944a293ba063a8 (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
46
47
48
49
50
import { injectable } from "tsyringe";
import * as messages from "../../shared/messages";

export default interface ConsoleClient {
  showCommand(tabId: number, command: string): Promise<any>;

  showFind(tabId: number): Promise<any>;

  showInfo(tabId: number, message: string): Promise<any>;

  showError(tabId: number, message: string): Promise<any>;

  hide(tabId: number): Promise<any>;
}

@injectable()
export class ConsoleClientImpl implements ConsoleClient {
  showCommand(tabId: number, command: string): Promise<any> {
    return browser.tabs.sendMessage(tabId, {
      type: messages.CONSOLE_SHOW_COMMAND,
      command,
    });
  }

  showFind(tabId: number): Promise<any> {
    return browser.tabs.sendMessage(tabId, {
      type: messages.CONSOLE_SHOW_FIND,
    });
  }

  showInfo(tabId: number, message: string): Promise<any> {
    return browser.tabs.sendMessage(tabId, {
      type: messages.CONSOLE_SHOW_INFO,
      text: message,
    });
  }

  showError(tabId: number, message: string): Promise<any> {
    return browser.tabs.sendMessage(tabId, {
      type: messages.CONSOLE_SHOW_ERROR,
      text: message,
    });
  }

  hide(tabId: number): Promise<any> {
    return browser.tabs.sendMessage(tabId, {
      type: messages.CONSOLE_HIDE,
    });
  }
}