send message to content instead of response
This commit is contained in:
parent
e15de17598
commit
3d35db9fc1
2 changed files with 5 additions and 19 deletions
|
@ -17,10 +17,7 @@ const keyPressHandle = (request, sender) => {
|
||||||
if (actions.isBackgroundAction(action.type)) {
|
if (actions.isBackgroundAction(action.type)) {
|
||||||
return doBackgroundAction(sender, action);
|
return doBackgroundAction(sender, action);
|
||||||
} else if (actions.isContentAction(action.type)) {
|
} else if (actions.isContentAction(action.type)) {
|
||||||
return Promise.resolve({
|
return browser.tabs.sendMessage(sender.tab.id, action);
|
||||||
type: 'response.action',
|
|
||||||
action: action
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,8 @@ import Follow from './follow';
|
||||||
|
|
||||||
let vvConsole = new ConsoleFrame(window);
|
let vvConsole = new ConsoleFrame(window);
|
||||||
|
|
||||||
const doAction = (action) => {
|
|
||||||
|
browser.runtime.onMessage.addListener((action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actions.CMD_OPEN:
|
case actions.CMD_OPEN:
|
||||||
vvConsole.showCommand('');
|
vvConsole.showCommand('');
|
||||||
|
@ -51,19 +52,8 @@ const doAction = (action) => {
|
||||||
histories.next(window);
|
histories.next(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
return Promise.resolve();
|
||||||
|
});
|
||||||
const handleResponse = (response) => {
|
|
||||||
if (!response) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(response.type) {
|
|
||||||
case 'response.action':
|
|
||||||
doAction(response.action);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener("keypress", (e) => {
|
window.addEventListener("keypress", (e) => {
|
||||||
if (e.target instanceof HTMLInputElement) {
|
if (e.target instanceof HTMLInputElement) {
|
||||||
|
@ -77,7 +67,6 @@ window.addEventListener("keypress", (e) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.runtime.sendMessage(request)
|
browser.runtime.sendMessage(request)
|
||||||
.then(handleResponse)
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error("Vim Vixen:", err);
|
console.error("Vim Vixen:", err);
|
||||||
vvConsole.showError(err.message);
|
vvConsole.showError(err.message);
|
||||||
|
|
Reference in a new issue