aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers/CompletionController.ts
blob: b00a0cb9f8bf30967c0860936fa823261f477a7a (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
import {
  ConsoleGetCompletionTypesResponse,
  ConsoleGetPropertiesResponse,
  ConsoleRequestBookmarksResponse,
  ConsoleRequestHistoryResponse,
  ConsoleRequestSearchEnginesResponse,
  ConsoleRequestTabsResponse,
} from "../../shared/messages";
import { injectable } from "tsyringe";
import OpenCompletionUseCase from "../completion/OpenCompletionUseCase";
import TabCompletionUseCase from "../completion/TabCompletionUseCase";
import PropertyCompletionUseCase from "../completion/PropertyCompletionUseCase";

@injectable()
export default class CompletionController {
  constructor(
    private completionUseCase: OpenCompletionUseCase,
    private tabCompletionUseCase: TabCompletionUseCase,
    private propertyCompletionUseCase: PropertyCompletionUseCase
  ) {}

  async getCompletionTypes(): Promise<ConsoleGetCompletionTypesResponse> {
    return this.completionUseCase.getCompletionTypes();
  }

  async requestSearchEngines(
    query: string
  ): Promise<ConsoleRequestSearchEnginesResponse> {
    const items = await this.completionUseCase.requestSearchEngines(query);
    return items.map((name) => ({ title: name }));
  }

  async requestBookmarks(
    query: string
  ): Promise<ConsoleRequestBookmarksResponse> {
    return this.completionUseCase.requestBookmarks(query);
  }

  async requestHistory(query: string): Promise<ConsoleRequestHistoryResponse> {
    return this.completionUseCase.requestHistory(query);
  }

  async queryTabs(
    query: string,
    excludePinned: boolean
  ): Promise<ConsoleRequestTabsResponse> {
    return this.tabCompletionUseCase.queryTabs(query, excludePinned);
  }

  async getProperties(): Promise<ConsoleGetPropertiesResponse> {
    return this.propertyCompletionUseCase.getProperties();
  }
}