aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-05-02 17:25:56 +0900
committerGitHub <noreply@github.com>2020-05-02 17:25:56 +0900
commit5df0537bcf65a341e79852b1b30379c73318529c (patch)
treeaee5efe52412855f620cb514a13a2c14373f27b7 /src/background/infrastructures
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'src/background/infrastructures')
-rw-r--r--src/background/infrastructures/ConsoleClient.ts7
-rw-r--r--src/background/infrastructures/ContentMessageClient.ts8
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts153
-rw-r--r--src/background/infrastructures/MemoryStorage.ts6
4 files changed, 91 insertions, 83 deletions
diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts
index 1385fe7..8d0af89 100644
--- a/src/background/infrastructures/ConsoleClient.ts
+++ b/src/background/infrastructures/ConsoleClient.ts
@@ -1,5 +1,5 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
@injectable()
export default class ConsoleClient {
@@ -12,7 +12,7 @@ export default class ConsoleClient {
showFind(tabId: number): Promise<any> {
return browser.tabs.sendMessage(tabId, {
- type: messages.CONSOLE_SHOW_FIND
+ type: messages.CONSOLE_SHOW_FIND,
});
}
@@ -36,4 +36,3 @@ export default class ConsoleClient {
});
}
}
-
diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts
index b6c0c23..e889392 100644
--- a/src/background/infrastructures/ContentMessageClient.ts
+++ b/src/background/infrastructures/ContentMessageClient.ts
@@ -1,12 +1,12 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
@injectable()
export default class ContentMessageClient {
async broadcastSettingsChanged(): Promise<void> {
const tabs = await browser.tabs.query({});
for (const tab of tabs) {
- if (!tab.id || tab.url && tab.url.startsWith('about:')) {
+ if (!tab.id || (tab.url && tab.url.startsWith("about:"))) {
continue;
}
browser.tabs.sendMessage(tab.id, {
@@ -19,7 +19,7 @@ export default class ContentMessageClient {
const enabled = await browser.tabs.sendMessage(tabId, {
type: messages.ADDON_ENABLED_QUERY,
});
- return enabled as any as boolean;
+ return (enabled as any) as boolean;
}
async toggleAddonEnabled(tabId: number): Promise<void> {
diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 2fbb9cf..6978d35 100644
--- a/src/background/infrastructures/ContentMessageListener.ts
+++ b/src/background/infrastructures/ContentMessageListener.ts
@@ -1,18 +1,18 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
-import * as operations from '../../shared/operations';
-import CommandController from '../controllers/CommandController';
-import SettingController from '../controllers/SettingController';
-import FindController from '../controllers/FindController';
-import AddonEnabledController from '../controllers/AddonEnabledController';
-import LinkController from '../controllers/LinkController';
-import OperationController from '../controllers/OperationController';
-import MarkController from '../controllers/MarkController';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
+import * as operations from "../../shared/operations";
+import CommandController from "../controllers/CommandController";
+import SettingController from "../controllers/SettingController";
+import FindController from "../controllers/FindController";
+import AddonEnabledController from "../controllers/AddonEnabledController";
+import LinkController from "../controllers/LinkController";
+import OperationController from "../controllers/OperationController";
+import MarkController from "../controllers/MarkController";
import CompletionController from "../controllers/CompletionController";
@injectable()
export default class ContentMessageListener {
- private consolePorts: {[tabId: number]: browser.runtime.Port};
+ private consolePorts: { [tabId: number]: browser.runtime.Port };
constructor(
private settingController: SettingController,
@@ -22,21 +22,29 @@ export default class ContentMessageListener {
private addonEnabledController: AddonEnabledController,
private linkController: LinkController,
private operationController: OperationController,
- private markController: MarkController,
+ private markController: MarkController
) {
this.consolePorts = {};
}
run(): void {
- browser.runtime.onMessage.addListener((
- message: any, sender: browser.runtime.MessageSender,
- ) => {
- try {
- const ret = this.onMessage(message, sender.tab as browser.tabs.Tab);
- if (!(ret instanceof Promise)) {
- return {};
- }
- return ret.catch((e) => {
+ browser.runtime.onMessage.addListener(
+ (message: any, sender: browser.runtime.MessageSender) => {
+ try {
+ const ret = this.onMessage(message, sender.tab as browser.tabs.Tab);
+ if (!(ret instanceof Promise)) {
+ return {};
+ }
+ return ret.catch((e) => {
+ if (!sender.tab || !sender.tab.id) {
+ return;
+ }
+ return browser.tabs.sendMessage(sender.tab.id, {
+ type: messages.CONSOLE_SHOW_ERROR,
+ text: e.message,
+ });
+ });
+ } catch (e) {
if (!sender.tab || !sender.tab.id) {
return;
}
@@ -44,64 +52,62 @@ export default class ContentMessageListener {
type: messages.CONSOLE_SHOW_ERROR,
text: e.message,
});
- });
- } catch (e) {
- if (!sender.tab || !sender.tab.id) {
- return;
}
- return browser.tabs.sendMessage(sender.tab.id, {
- type: messages.CONSOLE_SHOW_ERROR,
- text: e.message,
- });
}
- });
+ );
browser.runtime.onConnect.addListener(this.onConnected.bind(this));
}
onMessage(
- message: messages.Message, senderTab: browser.tabs.Tab,
+ message: messages.Message,
+ senderTab: browser.tabs.Tab
): Promise<any> | any {
switch (message.type) {
- case messages.CONSOLE_GET_COMPLETION_TYPES:
- return this.completionController.getCompletionTypes();
- case messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE:
- return this.completionController.requestSearchEngines(message.query);
- case messages.CONSOLE_REQUEST_BOOKMARKS:
- return this.completionController.requestBookmarks(message.query);
- case messages.CONSOLE_REQUEST_HISTORY:
- return this.completionController.requestHistory(message.query);
- case messages.CONSOLE_REQUEST_TABS:
- return this.completionController.queryTabs(message.query, message.excludePinned);
- case messages.CONSOLE_GET_PROPERTIES:
- return this.completionController.getProperties();
- case messages.CONSOLE_ENTER_COMMAND:
- return this.onConsoleEnterCommand(message.text);
- case messages.SETTINGS_QUERY:
- return this.onSettingsQuery();
- case messages.FIND_GET_KEYWORD:
- return this.onFindGetKeyword();
- case messages.FIND_SET_KEYWORD:
- return this.onFindSetKeyword(message.keyword);
- case messages.ADDON_ENABLED_RESPONSE:
- return this.onAddonEnabledResponse(message.enabled);
- case messages.OPEN_URL:
- return this.onOpenUrl(
- message.newTab,
- message.url,
- senderTab.id as number,
- message.background);
- case messages.BACKGROUND_OPERATION:
- return this.onBackgroundOperation(message.repeat, message.operation);
- case messages.MARK_SET_GLOBAL:
- return this.onMarkSetGlobal(message.key, message.x, message.y);
- case messages.MARK_JUMP_GLOBAL:
- return this.onMarkJumpGlobal(message.key);
- case messages.CONSOLE_FRAME_MESSAGE:
- return this.onConsoleFrameMessage(
- senderTab.id as number, message.message,
- );
+ case messages.CONSOLE_GET_COMPLETION_TYPES:
+ return this.completionController.getCompletionTypes();
+ case messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE:
+ return this.completionController.requestSearchEngines(message.query);
+ case messages.CONSOLE_REQUEST_BOOKMARKS:
+ return this.completionController.requestBookmarks(message.query);
+ case messages.CONSOLE_REQUEST_HISTORY:
+ return this.completionController.requestHistory(message.query);
+ case messages.CONSOLE_REQUEST_TABS:
+ return this.completionController.queryTabs(
+ message.query,
+ message.excludePinned
+ );
+ case messages.CONSOLE_GET_PROPERTIES:
+ return this.completionController.getProperties();
+ case messages.CONSOLE_ENTER_COMMAND:
+ return this.onConsoleEnterCommand(message.text);
+ case messages.SETTINGS_QUERY:
+ return this.onSettingsQuery();
+ case messages.FIND_GET_KEYWORD:
+ return this.onFindGetKeyword();
+ case messages.FIND_SET_KEYWORD:
+ return this.onFindSetKeyword(message.keyword);
+ case messages.ADDON_ENABLED_RESPONSE:
+ return this.onAddonEnabledResponse(message.enabled);
+ case messages.OPEN_URL:
+ return this.onOpenUrl(
+ message.newTab,
+ message.url,
+ senderTab.id as number,
+ message.background
+ );
+ case messages.BACKGROUND_OPERATION:
+ return this.onBackgroundOperation(message.repeat, message.operation);
+ case messages.MARK_SET_GLOBAL:
+ return this.onMarkSetGlobal(message.key, message.x, message.y);
+ case messages.MARK_JUMP_GLOBAL:
+ return this.onMarkJumpGlobal(message.key);
+ case messages.CONSOLE_FRAME_MESSAGE:
+ return this.onConsoleFrameMessage(
+ senderTab.id as number,
+ message.message
+ );
}
- throw new Error('unsupported message: ' + message.type);
+ throw new Error("unsupported message: " + message.type);
}
onConsoleEnterCommand(text: string): Promise<any> {
@@ -125,7 +131,10 @@ export default class ContentMessageListener {
}
onOpenUrl(
- newTab: boolean, url: string, openerId: number, background: boolean,
+ newTab: boolean,
+ url: string,
+ openerId: number,
+ background: boolean
): Promise<any> {
if (newTab) {
return this.linkController.openNewTab(url, openerId, background);
@@ -154,7 +163,7 @@ export default class ContentMessageListener {
}
onConnected(port: browser.runtime.Port): void {
- if (port.name !== 'vimvixen-console') {
+ if (port.name !== "vimvixen-console") {
return;
}
diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/infrastructures/MemoryStorage.ts
index af445a6..ad7bcd7 100644
--- a/src/background/infrastructures/MemoryStorage.ts
+++ b/src/background/infrastructures/MemoryStorage.ts
@@ -1,10 +1,10 @@
-const db: {[key: string]: any} = {};
+const db: { [key: string]: any } = {};
export default class MemoryStorage {
set(name: string, value: any): void {
const data = JSON.stringify(value);
- if (typeof data === 'undefined') {
- throw new Error('value is not serializable');
+ if (typeof data === "undefined") {
+ throw new Error("value is not serializable");
}
db[name] = data;
}