diff options
Diffstat (limited to 'src/background')
18 files changed, 114 insertions, 56 deletions
diff --git a/src/background/controllers/AddonEnabledController.ts b/src/background/controllers/AddonEnabledController.ts index 170abdf..fd69a69 100644 --- a/src/background/controllers/AddonEnabledController.ts +++ b/src/background/controllers/AddonEnabledController.ts @@ -5,7 +5,7 @@ import AddonEnabledUseCase from "../usecases/AddonEnabledUseCase"; export default class AddonEnabledController { constructor(private addonEnabledUseCase: AddonEnabledUseCase) {} - indicate(enabled: boolean): Promise<any> { + indicate(enabled: boolean): Promise<void> { return this.addonEnabledUseCase.indicate(enabled); } } diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index f19303f..bde401a 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -11,7 +11,7 @@ export default class CommandController { constructor(private commandIndicator: CommandUseCase) {} // eslint-disable-next-line complexity - exec(line: string): Promise<any> { + exec(line: string): Promise<unknown> { const trimmed = trimStart(line); const words = trimmed.split(/ +/); const name = words[0]; diff --git a/src/background/controllers/ConsoleController.ts b/src/background/controllers/ConsoleController.ts new file mode 100644 index 0000000..11ee09d --- /dev/null +++ b/src/background/controllers/ConsoleController.ts @@ -0,0 +1,11 @@ +import { injectable } from "tsyringe"; +import ConsoleUseCase from "./ConsoleUseCase"; + +@injectable() +export default class ConsoleController { + constructor(private readonly consoleUseCase: ConsoleUseCase) {} + + resize(width: number, height: number) { + return this.consoleUseCase.resize(width, height); + } +} diff --git a/src/background/controllers/ConsoleFrameClient.ts b/src/background/controllers/ConsoleFrameClient.ts new file mode 100644 index 0000000..170566d --- /dev/null +++ b/src/background/controllers/ConsoleFrameClient.ts @@ -0,0 +1,15 @@ +import * as messages from "../../shared/messages"; + +export default interface ConsoleFrameClient { + resize(tabId: number, width: number, height: number): Promise<void>; +} + +export class ConsoleFrameClientImpl implements ConsoleFrameClient { + async resize(tabId: number, width: number, height: number): Promise<void> { + await browser.tabs.sendMessage(tabId, { + type: messages.CONSOLE_RESIZE, + width, + height, + }); + } +} diff --git a/src/background/controllers/ConsoleUseCase.ts b/src/background/controllers/ConsoleUseCase.ts new file mode 100644 index 0000000..556aaf8 --- /dev/null +++ b/src/background/controllers/ConsoleUseCase.ts @@ -0,0 +1,21 @@ +import { inject, injectable } from "tsyringe"; +import ConsoleFrameClient from "./ConsoleFrameClient"; +import TabPresenter from "../presenters/TabPresenter"; + +@injectable() +export default class ConsoleUseCase { + constructor( + @inject("TabPresenter") + private readonly tabPresenter: TabPresenter, + @inject("ConsoleFrameClient") + private readonly consoleFrameClient: ConsoleFrameClient + ) {} + + async resize(width: number, height: number): Promise<void> { + const tabId = (await this.tabPresenter.getCurrent()).id; + if (typeof tabId === "undefined") { + return; + } + return this.consoleFrameClient.resize(tabId, width, height); + } +} diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts index 92dfeb0..f3ea93f 100644 --- a/src/background/controllers/FindController.ts +++ b/src/background/controllers/FindController.ts @@ -9,7 +9,7 @@ export default class FindController { return this.findUseCase.getKeyword(); } - setKeyword(keyword: string): Promise<any> { + setKeyword(keyword: string): Promise<void> { return this.findUseCase.setKeyword(keyword); } } diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts index 0d468f2..cfe425f 100644 --- a/src/background/controllers/MarkController.ts +++ b/src/background/controllers/MarkController.ts @@ -5,11 +5,11 @@ import MarkUseCase from "../usecases/MarkUseCase"; export default class MarkController { constructor(private markUseCase: MarkUseCase) {} - setGlobal(key: string, x: number, y: number): Promise<any> { + setGlobal(key: string, x: number, y: number): Promise<void> { return this.markUseCase.setGlobal(key, x, y); } - jumpGlobal(key: string): Promise<any> { + jumpGlobal(key: string): Promise<void> { return this.markUseCase.jumpGlobal(key); } } diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index d606ac0..7e43153 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -11,7 +11,7 @@ export default class OperationController { private readonly operatorFactory: OperatorFactory ) {} - async exec(repeat: number, op: operations.Operation): Promise<any> { + async exec(repeat: number, op: operations.Operation): Promise<void> { await this.doOperation(repeat, op); if (this.repeatUseCase.isRepeatable(op)) { this.repeatUseCase.storeLastOperation(op); @@ -21,7 +21,7 @@ export default class OperationController { private async doOperation( repeat: number, operation: operations.Operation - ): Promise<any> { + ): Promise<void> { const operator = this.operatorFactory.create(operation); for (let i = 0; i < repeat; ++i) { // eslint-disable-next-line no-await-in-loop diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts index 4248746..cc0b89f 100644 --- a/src/background/controllers/SettingController.ts +++ b/src/background/controllers/SettingController.ts @@ -14,7 +14,7 @@ export default class SettingController { return this.settingUseCase.getCached(); } - async reload(): Promise<any> { + async reload(): Promise<void> { await this.settingUseCase.reload(); this.contentMessageClient.broadcastSettingsChanged(); } diff --git a/src/background/di.ts b/src/background/di.ts index 358ff1e..3c43d2d 100644 --- a/src/background/di.ts +++ b/src/background/di.ts @@ -18,6 +18,7 @@ import { BrowserSettingRepositoryImpl } from "./repositories/BrowserSettingRepos import { RepeatRepositoryImpl } from "./repositories/RepeatRepository"; import { ZoomPresenterImpl } from "./presenters/ZoomPresenter"; import { WindowPresenterImpl } from "./presenters/WindowPresenter"; +import { ConsoleFrameClientImpl } from "./controllers/ConsoleFrameClient"; container.register("LocalSettingRepository", { useClass: LocalSettingRepository, @@ -41,4 +42,5 @@ container.register("TabPresenter", { useClass: TabPresenterImpl }); container.register("WindowPresenter", { useClass: WindowPresenterImpl }); container.register("NavigateClient", { useClass: NavigateClientImpl }); container.register("ConsoleClient", { useClass: ConsoleClientImpl }); +container.register("ConsoleFrameClient", { useClass: ConsoleFrameClientImpl }); container.register("OperatorFactory", { useClass: OperatorFactoryImpl }); diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts index 2a1df5b..f2d0e8a 100644 --- a/src/background/infrastructures/ConsoleClient.ts +++ b/src/background/infrastructures/ConsoleClient.ts @@ -2,47 +2,47 @@ import { injectable } from "tsyringe"; import * as messages from "../../shared/messages"; export default interface ConsoleClient { - showCommand(tabId: number, command: string): Promise<any>; + showCommand(tabId: number, command: string): Promise<void>; - showFind(tabId: number): Promise<any>; + showFind(tabId: number): Promise<void>; - showInfo(tabId: number, message: string): Promise<any>; + showInfo(tabId: number, message: string): Promise<void>; - showError(tabId: number, message: string): Promise<any>; + showError(tabId: number, message: string): Promise<void>; - hide(tabId: number): Promise<any>; + hide(tabId: number): Promise<void>; } @injectable() export class ConsoleClientImpl implements ConsoleClient { - showCommand(tabId: number, command: string): Promise<any> { + showCommand(tabId: number, command: string): Promise<void> { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_COMMAND, command, }); } - showFind(tabId: number): Promise<any> { + showFind(tabId: number): Promise<void> { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_FIND, }); } - showInfo(tabId: number, message: string): Promise<any> { + showInfo(tabId: number, message: string): Promise<void> { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_INFO, text: message, }); } - showError(tabId: number, message: string): Promise<any> { + showError(tabId: number, message: string): Promise<void> { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_ERROR, text: message, }); } - hide(tabId: number): Promise<any> { + hide(tabId: number): Promise<void> { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_HIDE, }); diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 6978d35..ec87938 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -9,23 +9,23 @@ import LinkController from "../controllers/LinkController"; import OperationController from "../controllers/OperationController"; import MarkController from "../controllers/MarkController"; import CompletionController from "../controllers/CompletionController"; +import ConsoleController from "../controllers/ConsoleController"; @injectable() export default class ContentMessageListener { - private consolePorts: { [tabId: number]: browser.runtime.Port }; + private readonly consolePorts: { [tabId: number]: browser.runtime.Port } = {}; constructor( - private settingController: SettingController, - private commandController: CommandController, - private completionController: CompletionController, - private findController: FindController, - private addonEnabledController: AddonEnabledController, - private linkController: LinkController, - private operationController: OperationController, - private markController: MarkController - ) { - this.consolePorts = {}; - } + private readonly settingController: SettingController, + private readonly commandController: CommandController, + private readonly completionController: CompletionController, + private readonly findController: FindController, + private readonly addonEnabledController: AddonEnabledController, + private readonly linkController: LinkController, + private readonly operationController: OperationController, + private readonly markController: MarkController, + private readonly consoleController: ConsoleController + ) {} run(): void { browser.runtime.onMessage.addListener( @@ -61,7 +61,7 @@ export default class ContentMessageListener { onMessage( message: messages.Message, senderTab: browser.tabs.Tab - ): Promise<any> | any { + ): Promise<unknown> | unknown { switch (message.type) { case messages.CONSOLE_GET_COMPLETION_TYPES: return this.completionController.getCompletionTypes(); @@ -80,6 +80,8 @@ export default class ContentMessageListener { return this.completionController.getProperties(); case messages.CONSOLE_ENTER_COMMAND: return this.onConsoleEnterCommand(message.text); + case messages.CONSOLE_RESIZE: + return this.onConsoleResize(message.width, message.height); case messages.SETTINGS_QUERY: return this.onSettingsQuery(); case messages.FIND_GET_KEYWORD: @@ -110,11 +112,15 @@ export default class ContentMessageListener { throw new Error("unsupported message: " + message.type); } - onConsoleEnterCommand(text: string): Promise<any> { + onConsoleEnterCommand(text: string): Promise<unknown> { return this.commandController.exec(text); } - async onSettingsQuery(): Promise<any> { + onConsoleResize(width: number, height: number): Promise<void> { + return this.consoleController.resize(width, height); + } + + async onSettingsQuery(): Promise<unknown> { return (await this.settingController.getSetting()).toJSON(); } @@ -122,11 +128,11 @@ export default class ContentMessageListener { return this.findController.getKeyword(); } - onFindSetKeyword(keyword: string): Promise<any> { + onFindSetKeyword(keyword: string): Promise<void> { return this.findController.setKeyword(keyword); } - onAddonEnabledResponse(enabled: boolean): Promise<any> { + onAddonEnabledResponse(enabled: boolean): Promise<void> { return this.addonEnabledController.indicate(enabled); } @@ -135,22 +141,25 @@ export default class ContentMessageListener { url: string, openerId: number, background: boolean - ): Promise<any> { + ): Promise<void> { if (newTab) { return this.linkController.openNewTab(url, openerId, background); } return this.linkController.openToTab(url, openerId); } - onBackgroundOperation(count: number, op: operations.Operation): Promise<any> { + onBackgroundOperation( + count: number, + op: operations.Operation + ): Promise<void> { return this.operationController.exec(count, op); } - onMarkSetGlobal(key: string, x: number, y: number): Promise<any> { + onMarkSetGlobal(key: string, x: number, y: number): Promise<void> { return this.markController.setGlobal(key, x, y); } - onMarkJumpGlobal(key: string): Promise<any> { + onMarkJumpGlobal(key: string): Promise<void> { return this.markController.jumpGlobal(key); } diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts index be56284..813e065 100644 --- a/src/background/repositories/FindRepository.ts +++ b/src/background/repositories/FindRepository.ts @@ -15,7 +15,7 @@ export default class FindRepository { return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY)); } - setKeyword(keyword: string): Promise<any> { + setKeyword(keyword: string): Promise<void> { this.cache.set(FIND_KEYWORD_KEY, keyword); return Promise.resolve(); } diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts index e2c1e94..493b25a 100644 --- a/src/background/repositories/MarkRepository.ts +++ b/src/background/repositories/MarkRepository.ts @@ -22,7 +22,7 @@ export default class MarkRepository { return Promise.resolve(mark); } - setMark(key: string, mark: GlobalMark): Promise<any> { + setMark(key: string, mark: GlobalMark): Promise<void> { const marks = this.getOrEmptyMarks(); marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y }; this.cache.set(MARK_KEY, marks); diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index 18ddd4d..29e6e7c 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -58,7 +58,7 @@ export default class CommandUseCase { } // eslint-disable-next-line max-statements - async buffer(keywords: string): Promise<any> { + async buffer(keywords: string): Promise<void> { if (keywords.length === 0) { return; } @@ -95,7 +95,7 @@ export default class CommandUseCase { return this.tabPresenter.select(tabs[0].id as number); } - async bdelete(force: boolean, keywords: string): Promise<any> { + async bdelete(force: boolean, keywords: string): Promise<void> { const excludePinned = !force; const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); if (tabs.length === 0) { @@ -106,32 +106,32 @@ export default class CommandUseCase { return this.tabPresenter.remove([tabs[0].id as number]); } - async bdeletes(force: boolean, keywords: string): Promise<any> { + async bdeletes(force: boolean, keywords: string): Promise<void> { const excludePinned = !force; const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); const ids = tabs.map((tab) => tab.id as number); return this.tabPresenter.remove(ids); } - async quit(): Promise<any> { + async quit(): Promise<void> { const tab = await this.tabPresenter.getCurrent(); return this.tabPresenter.remove([tab.id as number]); } - async quitAll(): Promise<any> { + async quitAll(): Promise<void> { const tabs = await this.tabPresenter.getAll(); const ids = tabs.map((tab) => tab.id as number); this.tabPresenter.remove(ids); } - async addbookmark(title: string): Promise<any> { + async addbookmark(title: string): Promise<void> { const tab = await this.tabPresenter.getCurrent(); const item = await this.bookmarkRepository.create(title, tab.url as string); const message = "Saved current page: " + item.url; return this.consoleClient.showInfo(tab.id as number, message); } - async set(keywords: string): Promise<any> { + async set(keywords: string): Promise<void> { if (keywords.length === 0) { return; } @@ -145,7 +145,7 @@ export default class CommandUseCase { return this.helpPresenter.open(); } - private async urlOrSearch(keywords: string): Promise<any> { + private async urlOrSearch(keywords: string): Promise<string> { const settings = await this.cachedSettingRepository.get(); return urls.searchUrl(keywords, settings.search); } diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index ce96e03..cc111f2 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -9,7 +9,7 @@ export default class FindUseCase { return this.findRepository.getKeyword(); } - setKeyword(keyword: string): Promise<any> { + setKeyword(keyword: string): Promise<void> { return this.findRepository.setKeyword(keyword); } } diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts index d2cd464..7fa3d9c 100644 --- a/src/background/usecases/LinkUseCase.ts +++ b/src/background/usecases/LinkUseCase.ts @@ -5,15 +5,15 @@ import TabPresenter from "../presenters/TabPresenter"; export default class LinkUseCase { constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {} - openToTab(url: string, tabId: number): Promise<any> { - return this.tabPresenter.open(url, tabId); + async openToTab(url: string, tabId: number): Promise<void> { + await this.tabPresenter.open(url, tabId); } async openNewTab( url: string, openerId: number, background: boolean - ): Promise<any> { + ): Promise<void> { const properties: any = { active: !background }; const platform = await browser.runtime.getPlatformInfo(); @@ -22,6 +22,6 @@ export default class LinkUseCase { properties.openerTabId = openerId; } - return this.tabPresenter.create(url, properties); + await this.tabPresenter.create(url, properties); } } diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index 57e04b4..e9640ee 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -15,13 +15,13 @@ export default class MarkUseCase { private readonly contentMessageClient: ContentMessageClient ) {} - async setGlobal(key: string, x: number, y: number): Promise<any> { + async setGlobal(key: string, x: number, y: number): Promise<void> { const tab = await this.tabPresenter.getCurrent(); const mark = { tabId: tab.id as number, url: tab.url as string, x, y }; return this.markRepository.setMark(key, mark); } - async jumpGlobal(key: string): Promise<any> { + async jumpGlobal(key: string): Promise<void> { const current = await this.tabPresenter.getCurrent(); const mark = await this.markRepository.getMark(key); |