aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-09 20:35:15 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-09 20:35:15 +0900
commite6c5aea0748a108fc2c8eccc233130d08a957fb8 (patch)
tree2a134d5753757fdafec1e4e747720d257010f322 /src
parent6a2bfc51baf22bcf66153076120d48d894a3967d (diff)
more broadcast message
Diffstat (limited to 'src')
-rw-r--r--src/console/console.js16
-rw-r--r--src/content/index.js18
2 files changed, 13 insertions, 21 deletions
diff --git a/src/console/console.js b/src/console/console.js
index 23a26ef..006f640 100644
--- a/src/console/console.js
+++ b/src/console/console.js
@@ -1,8 +1,5 @@
import './console.scss';
import Completion from './completion';
-import * as messages from '../shared/messages';
-
-const parent = window.parent;
// TODO consider object-oriented
var prevValue = "";
@@ -30,7 +27,7 @@ const keyupMessage = (input) => {
};
const handleBlur = () => {
- messages.send(parent, blurMessage());
+ return browser.runtime.sendMessage(blurMessage());
};
const completeNext = () => {
@@ -66,11 +63,9 @@ const completePrev = () => {
const handleKeydown = (e) => {
switch(e.keyCode) {
case KeyboardEvent.DOM_VK_ESCAPE:
- messages.send(parent, blurMessage());
- break;
+ return browser.runtime.sendMessage(blurMessage());
case KeyboardEvent.DOM_VK_RETURN:
- messages.send(parent, keydownMessage(e.target));
- break;
+ return browser.runtime.sendMessage(keydownMessage(e.target));
case KeyboardEvent.DOM_VK_TAB:
if (e.shiftKey) {
completePrev();
@@ -90,8 +85,8 @@ const handleKeyup = (e) => {
if (e.target.value === prevValue) {
return;
}
- messages.send(parent, keyupMessage(e.target));
prevValue = e.target.value;
+ return browser.runtime.sendMessage(keyupMessage(e.target));
};
window.addEventListener('load', () => {
@@ -115,9 +110,8 @@ const showCommand = (text) => {
completion = null;
let container = window.document.querySelector('#vimvixen-console-completion');
container.innerHTML = '';
- messages.send(parent, keyupMessage(input));
- return Promise.resolve();
+ return browser.runtime.sendMessage(keyupMessage(input));
}
const showError = (text) => {
diff --git a/src/content/index.js b/src/content/index.js
index a2a864d..bf90363 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,7 +1,6 @@
import * as scrolls from './scrolls';
import * as histories from './histories';
import * as actions from '../shared/actions';
-import * as messages from '../shared/messages';
import ConsoleFrame from '../console/console-frame';
import Follow from './follow';
@@ -84,28 +83,27 @@ const doCompletion = (line) => {
vvConsole.showError(err.message);
});
}
+ return Promise.resolve();
};
-messages.receive(window, (message) => {
- switch (message.type) {
+browser.runtime.onMessage.addListener((action) => {
+ switch (action.type) {
case 'vimvixen.command.blur':
if (!vvConsole.isErrorShown()) {
vvConsole.hide();
}
- break;
+ return Promise.resolve();
case 'vimvixen.command.enter':
- browser.runtime.sendMessage({
+ return browser.runtime.sendMessage({
type: 'event.cmd.enter',
- text: message.value
+ text: action.value
}).catch((err) => {
console.error("Vim Vixen:", err);
vvConsole.showError(err.message);
});
- break;
case 'vimvixen.command.change':
- doCompletion(message.value);
- break;
+ return doCompletion(action.value);
default:
- return;
+ return Promise.resolve();
}
});