From 69556533e172f32915f84413130ff2630804f5ec Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 12 Dec 2019 19:59:43 -0500 Subject: [PATCH] Fix command handling --- ext/bg/js/backend.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 877161c7..fb680304 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -42,7 +42,7 @@ class Backend { this.onOptionsUpdated('background'); 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)); @@ -67,10 +67,6 @@ class Backend { }); } - onCommand(command) { - apiCommandExec(command); - } - onMessage({action, params}, sender, callback) { const handler = Backend._messageHandlers.get(action); if (typeof handler !== 'function') { return false; } @@ -184,6 +180,14 @@ class Backend { // NOP } + _runCommand(command, params) { + const handler = Backend._commandHandlers.get(command); + if (typeof handler !== 'function') { return false; } + + handler(this, params); + return true; + } + // Message handlers _onApiOptionsGet({optionsContext}) { @@ -398,10 +402,7 @@ class Backend { } async _onApiCommandExec({command, params}) { - const handler = Backend._commandHandlers.get(command); - if (typeof handler !== 'function') { return false; } - - handler(this, params); + return this._runCommand(command, params); } async _onApiAudioGetUrl({definition, source, optionsContext}) {