Fix command handling
This commit is contained in:
parent
b1f72905cf
commit
69556533e1
@ -42,7 +42,7 @@ class Backend {
|
|||||||
this.onOptionsUpdated('background');
|
this.onOptionsUpdated('background');
|
||||||
|
|
||||||
if (chrome.commands !== null && typeof chrome.commands === 'object') {
|
if (chrome.commands !== null && typeof chrome.commands === 'object') {
|
||||||
chrome.commands.onCommand.addListener(this.onCommand.bind(this));
|
chrome.commands.onCommand.addListener((command) => this._runCommand(command));
|
||||||
}
|
}
|
||||||
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
||||||
|
|
||||||
@ -67,10 +67,6 @@ class Backend {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCommand(command) {
|
|
||||||
apiCommandExec(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessage({action, params}, sender, callback) {
|
onMessage({action, params}, sender, callback) {
|
||||||
const handler = Backend._messageHandlers.get(action);
|
const handler = Backend._messageHandlers.get(action);
|
||||||
if (typeof handler !== 'function') { return false; }
|
if (typeof handler !== 'function') { return false; }
|
||||||
@ -184,6 +180,14 @@ class Backend {
|
|||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_runCommand(command, params) {
|
||||||
|
const handler = Backend._commandHandlers.get(command);
|
||||||
|
if (typeof handler !== 'function') { return false; }
|
||||||
|
|
||||||
|
handler(this, params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Message handlers
|
// Message handlers
|
||||||
|
|
||||||
_onApiOptionsGet({optionsContext}) {
|
_onApiOptionsGet({optionsContext}) {
|
||||||
@ -398,10 +402,7 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _onApiCommandExec({command, params}) {
|
async _onApiCommandExec({command, params}) {
|
||||||
const handler = Backend._commandHandlers.get(command);
|
return this._runCommand(command, params);
|
||||||
if (typeof handler !== 'function') { return false; }
|
|
||||||
|
|
||||||
handler(this, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onApiAudioGetUrl({definition, source, optionsContext}) {
|
async _onApiAudioGetUrl({definition, source, optionsContext}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user