[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Disable the webext if the bridge is unreachable



commit 685c3bd2626df5c2adc85b79b77624c980e12ef9
Author: Arlo Breault <arlolra@xxxxxxxxx>
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"
   },



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits