This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 62e9144f48c1dbc3fd854f0bd46c841aedff5748 Author: 5eba 5eba@untiy-mail.de AuthorDate: Sat Mar 19 08:29:54 2022 +0100
refactoring to use stats of webext also in badge --- init-badge.js | 4 +++- init-webext.js | 15 --------------- ui.js | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/init-badge.js b/init-badge.js index 171d5c0..8d4f4e6 100644 --- a/init-badge.js +++ b/init-badge.js @@ -67,7 +67,9 @@ class BadgeUI extends UI { } else { this.setIcon('on'); } - const total = 0; // FIXME: Share stats from webext + const total = this.stats.reduce((function(t, c) { + return t + c; + }), 0); this.popup.turnOn(clients, total); }
diff --git a/init-webext.js b/init-webext.js index 3b7decf..d527bb8 100644 --- a/init-webext.js +++ b/init-webext.js @@ -12,19 +12,9 @@ class WebExtUI extends UI { this.onConnect = this.onConnect.bind(this); this.onMessage = this.onMessage.bind(this); this.onDisconnect = this.onDisconnect.bind(this); - this.initStats(); chrome.runtime.onConnect.addListener(this.onConnect); }
- initStats() { - this.stats = [0]; - setInterval((() => { - this.stats.unshift(0); - this.stats.splice(24); - this.postActive(); - }), 60 * 60 * 1000); - } - checkNAT() { Util.checkNATType(config.datachannelTimeout).then((type) => { console.log("Setting NAT type: " + type); @@ -123,9 +113,6 @@ class WebExtUI extends UI {
setActive(connected) { super.setActive(connected); - if (connected) { - this.stats[0] += 1; - } this.postActive(); }
@@ -162,8 +149,6 @@ class WebExtUI extends UI {
WebExtUI.prototype.port = null;
-WebExtUI.prototype.stats = null; - WebExtUI.prototype.enabled = true;
/* diff --git a/ui.js b/ui.js index f667bef..f1d846a 100644 --- a/ui.js +++ b/ui.js @@ -4,9 +4,25 @@ All of Snowflake's DOM manipulation and inputs.
class UI {
+ constructor() { + this.initStats(); + } + + initStats() { + this.stats = [0]; + setInterval((() => { + this.stats.unshift(0); + this.stats.splice(24); + this.postActive(); + }), 60 * 60 * 1000); + } + setStatus() {}
setActive(connected) { + if (connected) { + this.stats[0] += 1; + } return this.active = connected; }
@@ -15,3 +31,4 @@ class UI { }
UI.prototype.active = false; +UI.prototype.stats = null;