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

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