receive message of console

jh-changes
Shin'ya Ueoka 7 years ago
parent 0eed357a5e
commit 6a2bfc51ba
  1. 6
      src/console/console-frame.js
  2. 24
      src/console/console.js

@ -1,5 +1,4 @@
import './console-frame.scss';
import * as messages from '../shared/messages';
export default class ConsoleFrame {
constructor(win) {
@ -33,9 +32,10 @@ export default class ConsoleFrame {
type: 'vimvixen.console.show.error',
text: text
};
messages.send(this.element.contentWindow, message);
this.errorShown = true;
this.element.blur();
return browser.runtime.sendMessage(message);
}
showFrame() {
@ -53,7 +53,7 @@ export default class ConsoleFrame {
}
setCompletions(completions) {
messages.send(this.element.contentWindow, {
return browser.runtime.sendMessage({
type: 'vimvixen.console.set.completions',
completions: completions
});

@ -116,6 +116,8 @@ const showCommand = (text) => {
let container = window.document.querySelector('#vimvixen-console-completion');
container.innerHTML = '';
messages.send(parent, keyupMessage(input));
return Promise.resolve();
}
const showError = (text) => {
@ -128,6 +130,8 @@ const showError = (text) => {
let completion = window.document.querySelector('#vimvixen-console-completion');
completion.style.display = 'none';
return Promise.resolve();
}
const createCompletionTitle = (text) => {
@ -177,6 +181,8 @@ const setCompletions = (completions) => {
let input = window.document.querySelector('#vimvixen-console-command-input');
completionOrigin = input.value.split(' ')[0];
return Promise.resolve();
}
const selectCompletion = (target) => {
@ -193,21 +199,15 @@ const selectCompletion = (target) => {
});
};
messages.receive(window, (message) => {
switch (message.type) {
case 'vimvixen.console.show.error':
showError(message.text);
break;
case 'vimvixen.console.set.completions':
setCompletions(message.completions);
break;
}
});
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case 'vimvixen.console.show.error':
return showError(action.text);
case 'vimvixen.console.set.completions':
return setCompletions(action.completions);
case 'vimvixen.console.show.command':
return showCommand(action.text);
}
default:
return Promise.resolve();
}
});