Disable the webext if the bridge is unreachable

This commit is contained in:
Arlo Breault 2019-09-25 22:23:14 -04:00
parent 19bc6d8858
commit 685c3bd262
2 changed files with 29 additions and 8 deletions

View file

@ -31,14 +31,32 @@ class WebExtUI extends UI {
this.setEnabled(false); this.setEnabled(false);
return; return;
} }
chrome.storage.local.get("snowflake-enabled", (result) => { (new Promise((resolve, reject) => {
let enabled = this.enabled; const ws = WS.makeWebsocket(config.relayAddr);
if (result['snowflake-enabled'] !== void 0) { ws.onopen = () => {
enabled = result['snowflake-enabled']; resolve();
} else { ws.close();
log("Toggle state not yet saved"); };
} ws.onerror = () => {
this.setEnabled(enabled); 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);
}); });
} }

View file

@ -23,6 +23,9 @@
"popupWebRTCOff": { "popupWebRTCOff": {
"message": "WebRTC feature is not detected." "message": "WebRTC feature is not detected."
}, },
"popupBridgeUnreachable": {
"message": "Could not connect to the bridge."
},
"popupDescOn": { "popupDescOn": {
"message": "Number of users your Snowflake has helped circumvent censorship in the last 24 hours: $1" "message": "Number of users your Snowflake has helped circumvent censorship in the last 24 hours: $1"
}, },