aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-03-14 22:57:56 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-03-14 23:05:18 +0900
commit04ebd1e5331d29b2413c174ae0fe9d73566b3b8d (patch)
tree49a1759615560fe13f6b1a5c416f274a7d0da91e /src/background
parentba19c573a76c75469b5b2ed9093f8373907ea364 (diff)
Resize console dynamically
Diffstat (limited to 'src/background')
-rw-r--r--src/background/controllers/ConsoleController.ts11
-rw-r--r--src/background/controllers/ConsoleFrameClient.ts15
-rw-r--r--src/background/controllers/ConsoleUseCase.ts21
-rw-r--r--src/background/di.ts2
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts30
5 files changed, 67 insertions, 12 deletions
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/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/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 26f98ab..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(
@@ -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:
@@ -114,6 +116,10 @@ export default class ContentMessageListener {
return this.commandController.exec(text);
}
+ onConsoleResize(width: number, height: number): Promise<void> {
+ return this.consoleController.resize(width, height);
+ }
+
async onSettingsQuery(): Promise<unknown> {
return (await this.settingController.getSetting()).toJSON();
}