Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Iframe dynamic resize #1034

Merged
merged 3 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Vim vixen",
"scripts": {
"schema": "ajv compile -s src/shared/settings/schema.json -o src/shared/settings/validate.js",
"start": "webpack --mode development -w --debug --devtool inline-source-map",
"start": "webpack --mode development -w --devtool inline-source-map",
"build": "NODE_ENV=production webpack --mode production --progress --devtool inline-source-map",
"package": "yarn build && script/package",
"lint": "eslint --ext .ts,.tsx .",
Expand Down
2 changes: 1 addition & 1 deletion src/background/controllers/AddonEnabledController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/background/controllers/CommandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 11 additions & 0 deletions src/background/controllers/ConsoleController.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
15 changes: 15 additions & 0 deletions src/background/controllers/ConsoleFrameClient.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
21 changes: 21 additions & 0 deletions src/background/controllers/ConsoleUseCase.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/background/controllers/FindController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/background/controllers/MarkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/background/controllers/OperationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/background/controllers/SettingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/background/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });
20 changes: 10 additions & 10 deletions src/background/infrastructures/ConsoleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
51 changes: 30 additions & 21 deletions src/background/infrastructures/ContentMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand All @@ -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:
Expand Down Expand Up @@ -110,23 +112,27 @@ 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();
}

onFindGetKeyword(): Promise<string> {
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);
}

Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/background/repositories/FindRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/background/repositories/MarkRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/background/usecases/CommandUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
Loading