aboutsummaryrefslogtreecommitdiff
path: root/src/console/clients/CompletionClient.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-03-26 22:17:00 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-03-26 22:17:00 +0900
commitb2a37b8fc3e273dd71e1e3558c58be8002aa3789 (patch)
tree9e6f0d354beca92e975dc97462b3860833112f81 /src/console/clients/CompletionClient.ts
parent6829e24c62c0291336502b3390905b57b81abd21 (diff)
Query completions on open command by a completion source
Diffstat (limited to 'src/console/clients/CompletionClient.ts')
-rw-r--r--src/console/clients/CompletionClient.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/console/clients/CompletionClient.ts b/src/console/clients/CompletionClient.ts
new file mode 100644
index 0000000..d5f9b01
--- /dev/null
+++ b/src/console/clients/CompletionClient.ts
@@ -0,0 +1,54 @@
+import * as messages from "../../shared/messages";
+import {
+ ConsoleGetCompletionTypesResponse,
+ ConsoleRequestBookmarksResponse,
+ ConsoleRequestHistoryResponse, ConsoleRequestSearchEnginesResponse
+} from "../../shared/messages";
+import CompletionType from "../../shared/CompletionType";
+
+export type SearchEngines = {
+ title: string
+}
+
+export type BookmarkItem = {
+ title: string
+ url: string
+}
+
+export type HistoryItem = {
+ title: string
+ url: string
+}
+
+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;
+ }
+}