From 7f07d30f56afecf49075dd252ceec43afcf51eb7 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:56:08 -0600 Subject: [PATCH] Embed port error-message into error-page This should ease troubleshooting for users. --- background.js | 36 ++++++++++++++++++++++-------------- html/error.html | 4 ++-- html/error.js | 6 ++++++ 3 files changed, 30 insertions(+), 16 deletions(-) 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.