From 5a7db96febd4e3cb2aa519610da75e0bccd69a7f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 23 May 2019 21:30:07 +0900 Subject: Move some navigation operations to background --- src/background/clients/NavigateClient.ts | 29 ++++++++++++++++ src/background/controllers/OperationController.ts | 10 ++++++ src/background/usecases/NavigateUseCase.ts | 40 +++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/background/clients/NavigateClient.ts create mode 100644 src/background/usecases/NavigateUseCase.ts (limited to 'src/background') diff --git a/src/background/clients/NavigateClient.ts b/src/background/clients/NavigateClient.ts new file mode 100644 index 0000000..bdd94ec --- /dev/null +++ b/src/background/clients/NavigateClient.ts @@ -0,0 +1,29 @@ +import { injectable } from 'tsyringe'; +import * as messages from '../../shared/messages'; + +@injectable() +export default class NavigateClient { + async historyNext(tabId: number): Promise { + await browser.tabs.sendMessage(tabId, { + type: messages.NAVIGATE_HISTORY_NEXT, + }); + } + + async historyPrev(tabId: number): Promise { + await browser.tabs.sendMessage(tabId, { + type: messages.NAVIGATE_HISTORY_PREV, + }); + } + + async linkNext(tabId: number): Promise { + await browser.tabs.sendMessage(tabId, { + type: messages.NAVIGATE_LINK_NEXT, + }); + } + + async linkPrev(tabId: number): Promise { + await browser.tabs.sendMessage(tabId, { + type: messages.NAVIGATE_LINK_PREV, + }); + } +} diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index de6f8cb..cb5c043 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -5,6 +5,7 @@ import ConsoleUseCase from '../usecases/ConsoleUseCase'; import TabUseCase from '../usecases/TabUseCase'; import TabSelectUseCase from '../usecases/TabSelectUseCase'; import ZoomUseCase from '../usecases/ZoomUseCase'; +import NavigateUseCase from '../usecases/NavigateUseCase'; @injectable() export default class OperationController { @@ -14,6 +15,7 @@ export default class OperationController { private tabUseCase: TabUseCase, private tabSelectUseCase: TabSelectUseCase, private zoomUseCase: ZoomUseCase, + private navigateUseCase: NavigateUseCase, ) { } @@ -74,6 +76,14 @@ export default class OperationController { return this.findUseCase.findStart(); case operations.CANCEL: return this.consoleUseCase.hideConsole(); + case operations.NAVIGATE_HISTORY_PREV: + return this.navigateUseCase.openHistoryPrev(); + case operations.NAVIGATE_HISTORY_NEXT: + return this.navigateUseCase.openHistoryNext(); + case operations.NAVIGATE_LINK_PREV: + return this.navigateUseCase.openLinkPrev(); + case operations.NAVIGATE_LINK_NEXT: + return this.navigateUseCase.openLinkNext(); } throw new Error('unknown operation: ' + operation.type); } diff --git a/src/background/usecases/NavigateUseCase.ts b/src/background/usecases/NavigateUseCase.ts new file mode 100644 index 0000000..76e1c8e --- /dev/null +++ b/src/background/usecases/NavigateUseCase.ts @@ -0,0 +1,40 @@ +import { injectable } from 'tsyringe'; +import NavigateClient from '../clients/NavigateClient'; +import TabPresenter from '../presenters/TabPresenter'; + +@injectable() +export default class NavigateUseCase { + constructor( + private tabPresenter: TabPresenter, + private navigateClient: NavigateClient, + ) { + } + + async openHistoryNext(): Promise { + let tab = await this.tabPresenter.getCurrent(); + await this.navigateClient.historyNext(tab.id!!); + } + + async openHistoryPrev(): Promise { + let tab = await this.tabPresenter.getCurrent(); + await this.navigateClient.historyPrev(tab.id!!); + } + + async openLinkNext(): Promise { + let tab = await this.tabPresenter.getCurrent(); + await this.navigateClient.linkNext(tab.id!!); + } + + async openLinkPrev(): Promise { + let tab = await this.tabPresenter.getCurrent(); + await this.navigateClient.linkPrev(tab.id!!); + } + + openParent(): Promise { + throw new Error('not implemented'); + } + + openRoot(): Promise { + throw new Error('not implemented'); + } +} -- cgit v1.2.3