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 failed to run command

-

+

-

It seems that Shellfox is not fully installed!

+

It seems that Shellfox is not fully installed!

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.

Completing installation

diff --git a/html/error.js b/html/error.js index 68e1ec9..5cb8abc 100644 --- a/html/error.js +++ b/html/error.js @@ -1,3 +1,9 @@ +let urlParams = location.toString().split("?error="); +if (urlParams && urlParams.length > 0) { + let errorText = unescape(urlParams[urlParams.length - 1]); + document.getElementById("error").innerText = "«" + errorText + "»"; +} + document.getElementsByTagName("html")[0].setAttribute("lang", browser.i18n.getMessage("@@ui_locale")); document.getElementById("errorPageTitle").innerText = browser.i18n.getMessage("errorPageTitle");