aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers/CompletionController.ts
blob: fb6137ca374c4b8f906103f6c9309331b8d00330 (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
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();
  }
}