aboutsummaryrefslogtreecommitdiff
path: root/src/console/clients/CompletionClient.ts
blob: a80918bc2d615bcdebf71213f6f72ebf2b5d52bb (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as messages from "../../shared/messages";
import {
  ConsoleGetCompletionTypesResponse,
  ConsoleGetPropertiesResponse,
  ConsoleRequestBookmarksResponse,
  ConsoleRequestHistoryResponse,
  ConsoleRequestSearchEnginesResponse,
  ConsoleRequestTabsResponse,
} from "../../shared/messages";
import CompletionType from "../../shared/CompletionType";
import TabFlag from "../../shared/TabFlag";

export type SearchEngines = {
  title: string;
};

export type BookmarkItem = {
  title: string;
  url: string;
};

export type HistoryItem = {
  title: string;
  url: string;
};

export type TabItem = {
  index: number;
  flag: TabFlag;
  title: string;
  url: string;
  faviconUrl?: string;
};

export type Property = {
  name: string;
  type: "string" | "boolean" | "number";
};

export default class CompletionClient {
  async getCompletionTypes(): Promise<CompletionType[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_GET_COMPLETION_TYPES,
    })) as ConsoleGetCompletionTypesResponse;
    return resp;
  }

  async requestSearchEngines(query: string): Promise<SearchEngines[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE,
      query,
    })) as ConsoleRequestSearchEnginesResponse;
    return resp;
  }

  async requestBookmarks(query: string): Promise<BookmarkItem[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_REQUEST_BOOKMARKS,
      query,
    })) as ConsoleRequestBookmarksResponse;
    return resp;
  }

  async requestHistory(query: string): Promise<HistoryItem[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_REQUEST_HISTORY,
      query,
    })) as ConsoleRequestHistoryResponse;
    return resp;
  }

  async requestTabs(query: string, excludePinned: boolean): Promise<TabItem[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_REQUEST_TABS,
      query,
      excludePinned,
    })) as ConsoleRequestTabsResponse;
    return resp;
  }

  async getProperties(): Promise<Property[]> {
    const resp = (await browser.runtime.sendMessage({
      type: messages.CONSOLE_GET_PROPERTIES,
    })) as ConsoleGetPropertiesResponse;
    return resp;
  }
}