commit 685c3bd2626df5c2adc85b79b77624c980e12ef9 Author: Arlo Breault arlolra@gmail.com Date: Wed Sep 25 22:23:14 2019 -0400
Disable the webext if the bridge is unreachable --- proxy/init-webext.js | 34 +++++++++++++++++++++++-------- proxy/static/_locales/en_US/messages.json | 3 +++ 2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/proxy/init-webext.js b/proxy/init-webext.js index b45f2df..dff1208 100644 --- a/proxy/init-webext.js +++ b/proxy/init-webext.js @@ -31,14 +31,32 @@ class WebExtUI extends UI { this.setEnabled(false); return; } - chrome.storage.local.get("snowflake-enabled", (result) => { - let enabled = this.enabled; - if (result['snowflake-enabled'] !== void 0) { - enabled = result['snowflake-enabled']; - } else { - log("Toggle state not yet saved"); - } - this.setEnabled(enabled); + (new Promise((resolve, reject) => { + const ws = WS.makeWebsocket(config.relayAddr); + ws.onopen = () => { + resolve(); + ws.close(); + }; + ws.onerror = () => { + this.missingFeature = 'popupBridgeUnreachable'; + this.setEnabled(false); + reject('Could not connect to bridge.'); + ws.close(); + }; + })) + .then(() => { + chrome.storage.local.get("snowflake-enabled", (result) => { + let enabled = this.enabled; + if (result['snowflake-enabled'] !== void 0) { + enabled = result['snowflake-enabled']; + } else { + log("Toggle state not yet saved"); + } + this.setEnabled(enabled); + }); + }) + .catch((e) => { + log(e); }); }
diff --git a/proxy/static/_locales/en_US/messages.json b/proxy/static/_locales/en_US/messages.json index f6ed740..1ac15d9 100644 --- a/proxy/static/_locales/en_US/messages.json +++ b/proxy/static/_locales/en_US/messages.json @@ -23,6 +23,9 @@ "popupWebRTCOff": { "message": "WebRTC feature is not detected." }, + "popupBridgeUnreachable": { + "message": "Could not connect to the bridge." + }, "popupDescOn": { "message": "Number of users your Snowflake has helped circumvent censorship in the last 24 hours: $1" },