Move missingFeature to initToggle in webext

This commit is contained in:
Arlo Breault 2019-09-25 21:33:57 -04:00
parent 3c28380bc6
commit 19bc6d8858
2 changed files with 44 additions and 49 deletions

View file

@ -18,46 +18,52 @@ class WebExtUI extends UI {
initStats() { initStats() {
this.stats = [0]; this.stats = [0];
return setInterval((() => { setInterval((() => {
this.stats.unshift(0); this.stats.unshift(0);
this.stats.splice(24); this.stats.splice(24);
return this.postActive(); this.postActive();
}), 60 * 60 * 1000); }), 60 * 60 * 1000);
} }
initToggle() { initToggle() {
if (!Util.hasWebRTC()) {
this.missingFeature = 'popupWebRTCOff';
this.setEnabled(false);
return;
}
chrome.storage.local.get("snowflake-enabled", (result) => { chrome.storage.local.get("snowflake-enabled", (result) => {
let enabled = this.enabled;
if (result['snowflake-enabled'] !== void 0) { if (result['snowflake-enabled'] !== void 0) {
this.enabled = result['snowflake-enabled']; enabled = result['snowflake-enabled'];
} else { } else {
log("Toggle state not yet saved"); log("Toggle state not yet saved");
} }
this.setEnabled(this.enabled); this.setEnabled(enabled);
}); });
} }
postActive() { postActive() {
var ref; this.setIcon();
return (ref = this.port) != null ? ref.postMessage({ if (!this.port) { return; }
this.port.postMessage({
active: this.active, active: this.active,
total: this.stats.reduce((function(t, c) { total: this.stats.reduce((function(t, c) {
return t + c; return t + c;
}), 0), }), 0),
enabled: this.enabled enabled: this.enabled,
}) : void 0; missingFeature: this.missingFeature,
});
} }
onConnect(port) { onConnect(port) {
this.port = port; this.port = port;
port.onDisconnect.addListener(this.onDisconnect); port.onDisconnect.addListener(this.onDisconnect);
port.onMessage.addListener(this.onMessage); port.onMessage.addListener(this.onMessage);
return this.postActive(); this.postActive();
} }
onMessage(m) { onMessage(m) {
this.enabled = m.enabled; this.setEnabled(m.enabled);
this.setEnabled(this.enabled);
this.postActive();
chrome.storage.local.set({ chrome.storage.local.set({
"snowflake-enabled": this.enabled "snowflake-enabled": this.enabled
}, function() { }, function() {
@ -75,30 +81,34 @@ class WebExtUI extends UI {
this.stats[0] += 1; this.stats[0] += 1;
} }
this.postActive(); this.postActive();
if (this.active) {
return chrome.browserAction.setIcon({
path: {
48: "assets/toolbar-running-48.png",
96: "assets/toolbar-running-96.png"
}
});
} else {
return chrome.browserAction.setIcon({
path: {
48: "assets/toolbar-on-48.png",
96: "assets/toolbar-on-96.png"
}
});
}
} }
setEnabled(enabled) { setEnabled(enabled) {
this.enabled = enabled;
this.postActive();
update(); update();
return chrome.browserAction.setIcon({ }
path: {
48: "assets/toolbar-" + (enabled ? "on" : "off") + "-48.png", setIcon() {
96: "assets/toolbar-" + (enabled ? "on" : "off") + "-96.png" let path = null;
} if (!this.enabled) {
path = {
48: "assets/toolbar-off-48.png",
96: "assets/toolbar-off-96.png"
};
} else if (this.active) {
path = {
48: "assets/toolbar-running-48.png",
96: "assets/toolbar-running-96.png"
};
} else {
path = {
48: "assets/toolbar-on-48.png",
96: "assets/toolbar-on-96.png"
};
}
chrome.browserAction.setIcon({
path: path,
}); });
} }
@ -139,28 +149,13 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
} }
}; };
if (!Util.hasWebRTC()) {
chrome.runtime.onConnect.addListener(function(port) {
return port.postMessage({
missingFeature: true
});
});
chrome.browserAction.setIcon({
path: {
48: "assets/toolbar-off-48.png",
96: "assets/toolbar-off-96.png"
}
});
return;
}
init = function() { init = function() {
config = new Config; config = new Config;
ui = new WebExtUI(); ui = new WebExtUI();
broker = new Broker(config.brokerUrl); broker = new Broker(config.brokerUrl);
snowflake = new Snowflake(config, ui, broker); snowflake = new Snowflake(config, ui, broker);
log('== snowflake proxy =='); log('== snowflake proxy ==');
return ui.initToggle(); ui.initToggle();
}; };
update = function() { update = function() {

View file

@ -19,7 +19,7 @@ port.onMessage.addListener((m) => {
popup.setEnabled(false); popup.setEnabled(false);
popup.setActive(false); popup.setActive(false);
popup.setStatusText(chrome.i18n.getMessage('popupStatusOff')); popup.setStatusText(chrome.i18n.getMessage('popupStatusOff'));
popup.setStatusDesc(chrome.i18n.getMessage('popupWebRTCOff'), true); popup.setStatusDesc(chrome.i18n.getMessage(missingFeature), true);
popup.hideButton(); popup.hideButton();
return; return;
} }