aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/controllers')
-rw-r--r--src/background/controllers/CommandController.ts38
-rw-r--r--src/background/controllers/CompletionController.ts47
2 files changed, 47 insertions, 38 deletions
diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts
index 7297ef8..16aa6e8 100644
--- a/src/background/controllers/CommandController.ts
+++ b/src/background/controllers/CommandController.ts
@@ -1,7 +1,5 @@
import { injectable } from 'tsyringe';
-import CompletionsUseCase from '../usecases/CompletionsUseCase';
import CommandUseCase from '../usecases/CommandUseCase';
-import CompletionGroup from '../domains/CompletionGroup';
const trimStart = (str: string): string => {
// NOTE String.trimStart is available on Firefox 61
@@ -11,46 +9,10 @@ const trimStart = (str: string): string => {
@injectable()
export default class CommandController {
constructor(
- private completionsUseCase: CompletionsUseCase,
private commandIndicator: CommandUseCase,
) {
}
- getCompletions(line: string): Promise<CompletionGroup[]> {
- const trimmed = trimStart(line);
- const words = trimmed.split(/ +/);
- const name = words[0];
- if (words.length === 1) {
- return this.completionsUseCase.queryConsoleCommand(name);
- }
- const keywords = trimStart(trimmed.slice(name.length));
- switch (words[0]) {
- case 'o':
- case 'open':
- case 't':
- case 'tabopen':
- case 'w':
- case 'winopen':
- return this.completionsUseCase.queryOpen(name, keywords);
- case 'b':
- case 'buffer':
- return this.completionsUseCase.queryBuffer(name, keywords);
- case 'bd':
- case 'bdel':
- case 'bdelete':
- case 'bdeletes':
- return this.completionsUseCase.queryBdelete(name, keywords);
- case 'bd!':
- case 'bdel!':
- case 'bdelete!':
- case 'bdeletes!':
- return this.completionsUseCase.queryBdeleteForce(name, keywords);
- case 'set':
- return this.completionsUseCase.querySet(name, keywords);
- }
- return Promise.resolve([]);
- }
-
// eslint-disable-next-line complexity
exec(line: string): Promise<any> {
const trimmed = trimStart(line);
diff --git a/src/background/controllers/CompletionController.ts b/src/background/controllers/CompletionController.ts
new file mode 100644
index 0000000..fb6137c
--- /dev/null
+++ b/src/background/controllers/CompletionController.ts
@@ -0,0 +1,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();
+ }
+} \ No newline at end of file