aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/controllers/OperationController.ts3
-rw-r--r--src/background/usecases/CommandUseCase.ts17
-rw-r--r--src/background/usecases/RepeatUseCase.ts1
-rw-r--r--src/background/usecases/TabUseCase.ts15
4 files changed, 36 insertions, 0 deletions
diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts
index 7233c0e..51cff28 100644
--- a/src/background/controllers/OperationController.ts
+++ b/src/background/controllers/OperationController.ts
@@ -105,6 +105,9 @@ export default class OperationController {
}
return Promise.resolve();
}
+ case operations.INTERNAL_OPEN_URL:
+ return this.tabUseCase.openURL(
+ operation.url, operation.newTab, operation.newWindow);
}
throw new Error('unknown operation: ' + operation.type);
}
diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts
index 921a779..a526cfc 100644
--- a/src/background/usecases/CommandUseCase.ts
+++ b/src/background/usecases/CommandUseCase.ts
@@ -1,4 +1,5 @@
import { injectable } from 'tsyringe';
+import * as operations from '../../shared/operations';
import * as parsers from './parsers';
import * as urls from '../../shared/urls';
import TabPresenter from '../presenters/TabPresenter';
@@ -7,6 +8,7 @@ import SettingRepository from '../repositories/SettingRepository';
import BookmarkRepository from '../repositories/BookmarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient';
import ContentMessageClient from '../infrastructures/ContentMessageClient';
+import RepeatUseCase from '../usecases/RepeatUseCase';
@injectable()
export default class CommandIndicator {
@@ -17,21 +19,36 @@ export default class CommandIndicator {
private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient,
private contentMessageClient: ContentMessageClient,
+ private repeatUseCase: RepeatUseCase,
) {
}
async open(keywords: string): Promise<browser.tabs.Tab> {
let url = await this.urlOrSearch(keywords);
+ this.repeatUseCase.storeLastOperation({
+ type: operations.INTERNAL_OPEN_URL,
+ url,
+ });
return this.tabPresenter.open(url);
}
async tabopen(keywords: string): Promise<browser.tabs.Tab> {
let url = await this.urlOrSearch(keywords);
+ this.repeatUseCase.storeLastOperation({
+ type: operations.INTERNAL_OPEN_URL,
+ url,
+ newTab: true,
+ });
return this.tabPresenter.create(url);
}
async winopen(keywords: string): Promise<browser.windows.Window> {
let url = await this.urlOrSearch(keywords);
+ this.repeatUseCase.storeLastOperation({
+ type: operations.INTERNAL_OPEN_URL,
+ url,
+ newWindow: true,
+ });
return this.windowPresenter.create(url);
}
diff --git a/src/background/usecases/RepeatUseCase.ts b/src/background/usecases/RepeatUseCase.ts
index a005682..d78de34 100644
--- a/src/background/usecases/RepeatUseCase.ts
+++ b/src/background/usecases/RepeatUseCase.ts
@@ -42,6 +42,7 @@ export default class RepeatUseCase {
case operations.ZOOM_IN:
case operations.ZOOM_OUT:
case operations.ZOOM_NEUTRAL:
+ case operations.INTERNAL_OPEN_URL:
return true;
}
return false;
diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts
index 0239a87..31112a9 100644
--- a/src/background/usecases/TabUseCase.ts
+++ b/src/background/usecases/TabUseCase.ts
@@ -1,11 +1,13 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter';
+import WindowPresenter from '../presenters/WindowPresenter';
import BrowserSettingRepository from '../repositories/BrowserSettingRepository';
@injectable()
export default class TabUseCase {
constructor(
private tabPresenter: TabPresenter,
+ private windowPresenter: WindowPresenter,
private browserSettingRepository: BrowserSettingRepository,
) {
}
@@ -77,4 +79,17 @@ export default class TabUseCase {
this.tabPresenter.create(url);
}
}
+
+ async openURL(
+ url: string, newTab?: boolean, newWindow?: boolean,
+ ): Promise<void> {
+ if (newWindow) {
+ await this.windowPresenter.create(url);
+ } else if (newTab) {
+ await this.tabPresenter.create(url);
+ } else {
+ let tab = await this.tabPresenter.getCurrent();
+ await this.tabPresenter.open(url, tab.id);
+ }
+ }
}