GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 2ba8f859 authored by Arlo Breault's avatar Arlo Breault
Browse files

Add a button to retry probe

Trac: 33365
Trac: 33112
parent dc9d4fab
......@@ -22,7 +22,20 @@ class BadgeUI extends UI {
constructor() {
super();
this.popup = new Popup((...args) => messages.getMessage(...args));
this.popup = new Popup(
(...args) => messages.getMessage(...args),
(event) => {
if (event.target.checked) {
setSnowflakeCookie('1', COOKIE_LIFETIME);
} else {
setSnowflakeCookie('', COOKIE_EXPIRE);
}
update();
},
() => {
tryProbe();
}
);
}
setStatus() {}
......@@ -92,7 +105,7 @@ function getLang() {
return defaultLang;
}
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications, query;
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications, query, tryProbe;
(function() {
......@@ -116,21 +129,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
if (debug) { log(msg); }
};
update = function() {
const cookies = Parse.cookie(document.cookie);
if (cookies[COOKIE_NAME] !== '1') {
ui.turnOff();
snowflake.disable();
log('Currently not active.');
return;
}
if (!Util.hasWebRTC()) {
ui.missingFeature('popupWebRTCOff');
snowflake.disable();
return;
}
tryProbe = function() {
WS.probeWebsocket(config.relayAddr)
.then(
() => {
......@@ -148,6 +147,24 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
);
};
update = function() {
const cookies = Parse.cookie(document.cookie);
if (cookies[COOKIE_NAME] !== '1') {
ui.turnOff();
snowflake.disable();
log('Currently not active.');
return;
}
if (!Util.hasWebRTC()) {
ui.missingFeature('popupWebRTCOff');
snowflake.disable();
return;
}
tryProbe();
};
init = function() {
ui = new BadgeUI();
......@@ -164,15 +181,6 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
snowflake = new Snowflake(config, ui, broker);
log('== snowflake proxy ==');
update();
document.getElementById('enabled').addEventListener('change', (event) => {
if (event.target.checked) {
setSnowflakeCookie('1', COOKIE_LIFETIME);
} else {
setSnowflakeCookie('', COOKIE_EXPIRE);
}
update();
})
};
// Notification of closing tab with active proxy.
......
......@@ -25,6 +25,21 @@ class WebExtUI extends UI {
}), 60 * 60 * 1000);
}
tryProbe() {
WS.probeWebsocket(config.relayAddr)
.then(
() => {
this.missingFeature = false;
this.setEnabled(true);
},
() => {
log('Could not connect to bridge.');
this.missingFeature = 'popupBridgeUnreachable';
this.setEnabled(false);
}
);
}
initToggle() {
// First, check if we have our status stored
(new Promise((resolve) => {
......@@ -48,17 +63,7 @@ class WebExtUI extends UI {
this.setEnabled(false);
return;
}
WS.probeWebsocket(config.relayAddr)
.then(
() => {
this.setEnabled(true);
},
() => {
log('Could not connect to bridge.');
this.missingFeature = 'popupBridgeUnreachable';
this.setEnabled(false);
}
);
this.tryProbe();
});
}
......@@ -83,6 +88,11 @@ class WebExtUI extends UI {
}
onMessage(m) {
if (m.retry) {
// FIXME: Can set a retrying state here
this.tryProbe();
return;
}
(new Promise((resolve) => {
chrome.storage.local.set({ "snowflake-enabled": m.enabled }, resolve);
}))
......
......@@ -26,6 +26,12 @@
"popupDescOn": {
"message": "Number of users your Snowflake has helped circumvent censorship in the last 24 hours: $1"
},
"popupRetry": {
"message": "Retry"
},
"popupRetrying": {
"message": "Retrying ..."
},
"badgeCookiesOff": {
"message": "Cookies are not enabled."
},
......
......@@ -15,6 +15,7 @@
<div id="statusimg"></div>
<p id="statustext">__MSG_popupStatusOff__</p>
<p id="statusdesc"></p>
<button type="button" id="retry">__MSG_popupRetry__</button>
</div>
<div class="b button">
<label id="toggle" for="enabled">__MSG_popupEnabled__</label>
......
......@@ -10,12 +10,21 @@ function setClass(elem, className, cond) {
}
class Popup {
constructor(getMsgFunc) {
constructor(getMsgFunc, changeFunc, retryFunc) {
this.getMsgFunc = getMsgFunc;
this.enabled = document.getElementById('enabled');
this.enabled.addEventListener('change', changeFunc);
this.retry = document.getElementById('retry');
this.retry.addEventListener('click', () => {
this.setStatusDesc(getMsgFunc('popupRetrying'));
this.setRetry(false);
setTimeout(retryFunc, 1000); // Just some UI feedback
});
this.div = document.getElementById('active');
this.statustext = document.getElementById('statustext');
this.statusdesc = document.getElementById('statusdesc');
this.img = document.getElementById('statusimg');
this.button = document.querySelector('.button');
}
setEnabled(enabled) {
setClass(this.img, 'on', enabled);
......@@ -30,11 +39,14 @@ class Popup {
this.statusdesc.innerText = desc;
setClass(this.statusdesc, 'error', error);
}
hideButton() {
document.querySelector('.button').style.display = 'none';
setButton(hide) {
this.button.style.display = hide ? 'none' : 'block';
}
setRetry(display) {
this.retry.style.display = display ? 'inline-block' : 'none';
}
setChecked(checked) {
document.getElementById('enabled').checked = checked;
this.enabled.checked = checked;
}
static fill(n, func) {
switch(n.nodeType) {
......@@ -58,16 +70,19 @@ class Popup {
this.setStatusDesc((total > 0) ? this.getMsgFunc('popupDescOn', String(total)) : '');
this.setEnabled(true);
this.setActive(this.active);
this.setButton(false);
this.setRetry(false);
}
turnOff(desc, error) {
turnOff(desc, error, retry) {
this.setChecked(false);
this.setStatusText(this.getMsgFunc('popupStatusOff'));
this.setStatusDesc(desc ? this.getMsgFunc(desc) : '', error);
this.setEnabled(false);
this.setActive(false);
this.setButton(error);
this.setRetry(retry);
}
missingFeature(desc) {
this.turnOff(desc, true);
this.hideButton();
this.turnOff(desc, true, desc === 'popupBridgeUnreachable');
}
}
......@@ -13,7 +13,11 @@ const port = chrome.runtime.connect({
port.onMessage.addListener((m) => {
const { active, enabled, total, missingFeature } = m;
const popup = new Popup((...args) => chrome.i18n.getMessage(...args));
const popup = new Popup(
(...args) => chrome.i18n.getMessage(...args),
(event) => port.postMessage({ enabled: event.target.checked }),
() => port.postMessage({ retry: true })
);
if (missingFeature) {
popup.missingFeature(missingFeature);
......@@ -28,7 +32,3 @@ port.onMessage.addListener((m) => {
popup.turnOff();
}
});
document.addEventListener('change', (event) => {
port.postMessage({ enabled: event.target.checked });
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment