aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers
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/controllers
parentba19c573a76c75469b5b2ed9093f8373907ea364 (diff)
Resize console dynamically
Diffstat (limited to 'src/background/controllers')
-rw-r--r--src/background/controllers/ConsoleController.ts11
-rw-r--r--src/background/controllers/ConsoleFrameClient.ts15
-rw-r--r--src/background/controllers/ConsoleUseCase.ts21
3 files changed, 47 insertions, 0 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);
+ }
+}