diff --git a/background.js b/background.js index 3417e34..60729b4 100644 --- a/background.js +++ b/background.js @@ -3,22 +3,30 @@ let port = undefined; // Run the shellfox helper program. function initShellfoxProgram() { port = browser.runtime.connectNative("shellfox"); - port.onDisconnect.addListener((port) => { - console.log(port.error); - port = undefined; + if (!port) + shellfoxFailed(); + else + port.onDisconnect.addListener(shellfoxFailed); +} - // Tell the user about the error… - browser.tabs.query({"active": true}).then((tabs) => { - let openerTab = undefined; - if (tabs && tabs.length > 0) - openerTab = tabs[0].id; - browser.tabs.create({ - "active": true, - "url": "/html/error.html", - "openerTabId": openerTab - }) - }); +// Display an error when we fail to launch Shellfox’es script. +function shellfoxFailed() { + let error = port.error; + console.log(error); + port = undefined; + + // Tell the user about the error… + browser.tabs.query({"active": true}).then((tabs) => { + let openerTab = undefined; + if (tabs && tabs.length > 0) + openerTab = tabs[0].id; + + browser.tabs.create({ + "active": true, + "url": "/html/error.html?error=" + escape(error), + "openerTabId": openerTab + }) }); } diff --git a/html/error.html b/html/error.html index f99225a..4e8da64 100644 --- a/html/error.html +++ b/html/error.html @@ -7,9 +7,9 @@
Shellfox, unlike most extensions, requires a script to be installed on your computer. This script, shellfox.sh
, is what allows us to execute shell commands.