diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-09 10:38:37 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 10:38:37 +0900 |
commit | 1656d52d2cefb3846d968c6117484e6aefe7dabe (patch) | |
tree | ab58a99b832d2571e2168f2ee0e328bc12d9580e /src/console/clients | |
parent | c6c2da8547891b50aef2f08e5f36d258183831ff (diff) | |
parent | 5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff) |
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
Diffstat (limited to 'src/console/clients')
-rw-r--r-- | src/console/clients/CompletionClient.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/console/clients/CompletionClient.ts b/src/console/clients/CompletionClient.ts new file mode 100644 index 0000000..56dc665 --- /dev/null +++ b/src/console/clients/CompletionClient.ts @@ -0,0 +1,84 @@ +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; + } +} |