From 903c9c78b7965b3a046ad90af36e3cac676da452 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 18 Oct 2017 22:04:30 +0900 Subject: remove message propagation --- src/content/components/common/follow.js | 2 ++ src/content/components/common/index.js | 5 ++-- src/content/components/common/input.js | 3 --- src/content/components/common/keymapper.js | 3 --- .../components/top-content/follow-controller.js | 2 ++ src/content/components/top-content/index.js | 5 ++-- src/content/index.js | 12 ---------- src/shared/messages.js | 27 ++++++++++++++++++++++ 8 files changed, 37 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js index 92d8822..5688da3 100644 --- a/src/content/components/common/follow.js +++ b/src/content/components/common/follow.js @@ -34,6 +34,8 @@ export default class Follow { this.newTab = false; this.hints = {}; this.targets = []; + + messages.onMessage(this.onMessage.bind(this)); } update() { diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 5e977ae..98a2337 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -21,18 +21,19 @@ export default class Common { ]; this.reloadSettings(); + + messages.onMessage(this.onMessage.bind(this)); } update() { this.children.forEach(c => c.update()); } - onMessage(message, sender) { + onMessage(message) { switch (message.type) { case messages.SETTINGS_CHANGED: this.reloadSettings(); } - this.children.forEach(c => c.onMessage(message, sender)); } reloadSettings() { diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js index 8a7f82a..df09894 100644 --- a/src/content/components/common/input.js +++ b/src/content/components/common/input.js @@ -69,7 +69,4 @@ export default class InputComponent { e.target.getAttribute('contenteditable').toLowerCase() === 'true' || e.target.getAttribute('contenteditable').toLowerCase() === ''); } - - onMessage() { - } } diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index 2a57b28..655c3f2 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -28,7 +28,4 @@ export default class KeymapperComponent { this.store.dispatch(inputActions.clearKeys()); return true; } - - onMessage() { - } } diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.js index 29f40b3..7570cf8 100644 --- a/src/content/components/top-content/follow-controller.js +++ b/src/content/components/top-content/follow-controller.js @@ -17,6 +17,8 @@ export default class FollowController { this.state = {}; this.keys = []; this.producer = null; + + messages.onMessage(this.onMessage.bind(this)); } onMessage(message, sender) { diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index a2179da..c318901 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -14,19 +14,20 @@ export default class TopContent { // TODO make component consoleFrames.initialize(window.document); + + messages.onMessage(this.onMessage.bind(this)); } update() { this.children.forEach(c => c.update()); } - onMessage(message, sender) { + onMessage(message) { switch (message.type) { case messages.CONSOLE_HIDE_COMMAND: this.win.focus(); consoleFrames.blur(window.document); return Promise.resolve(); } - this.children.forEach(c => c.onMessage(message, sender)); } } diff --git a/src/content/index.js b/src/content/index.js index e01172d..77249f8 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -14,16 +14,4 @@ store.subscribe(() => { rootComponent.update(); }); -browser.runtime.onMessage.addListener(msg => rootComponent.onMessage(msg)); rootComponent.update(); - -window.addEventListener('message', (event) => { - let message = null; - try { - message = JSON.parse(event.data); - } catch (e) { - // ignore unexpected message - return; - } - rootComponent.onMessage(message, event.source); -}); diff --git a/src/shared/messages.js b/src/shared/messages.js index 134d71c..dc497b6 100644 --- a/src/shared/messages.js +++ b/src/shared/messages.js @@ -1,3 +1,26 @@ +const onWebMessage = (listener) => { + window.addEventListener('message', (event) => { + let sender = event.source; + let message = null; + try { + message = JSON.parse(event.data); + } catch (e) { + // ignore unexpected message + return; + } + listener(message, sender); + }); +}; + +const onBackgroundMessage = (listener) => { + browser.runtime.onMessage.addListener(listener); +}; + +const onMessage = (listener) => { + onWebMessage(listener); + onBackgroundMessage(listener); +}; + export default { BACKGROUND_OPERATION: 'background.operation', @@ -23,4 +46,8 @@ export default { SETTINGS_RELOAD: 'settings.reload', SETTINGS_CHANGED: 'settings.changed', SETTINGS_QUERY: 'settings.query', + + onWebMessage, + onBackgroundMessage, + onMessage, }; -- cgit v1.2.3 From 71d35005b4b33e90a85dc50964cb96a8b462b748 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 19 Oct 2017 20:31:16 +0900 Subject: force console focus --- src/console/components/console.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/console/components/console.js b/src/console/components/console.js index 82ec467..dcd4041 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -107,6 +107,8 @@ export default class ConsoleComponent { command.style.display = 'block'; input.value = text; input.focus(); + + window.focus(); this.prevValue = ''; } -- cgit v1.2.3