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.
The following commit(s) were added to refs/heads/main by this push: new b4743eb feat: show number of clients on the icon badge b4743eb is described below
commit b4743eb1c7c48019411e2c26b4e6e31ded836d66 Author: WofWca wofwca@protonmail.com AuthorDate: Wed Nov 9 13:46:08 2022 +0400
feat: show number of clients on the icon badge
Closes #50 --- init-webext.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/init-webext.js b/init-webext.js index 0a6c2b9..4bbeff9 100644 --- a/init-webext.js +++ b/init-webext.js @@ -181,25 +181,42 @@ class WebExtUI extends UI {
setIcon() { let path = null; + let badgeText = ''; 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" - }; + 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" + }; + } + + const totalClients = this.stats.reduce((t, c) => t + c, 0); + if (totalClients > 0) { + if (config.maxNumClients > 1 && this.clients > 0) { + // Like `19+3` + badgeText = `${totalClients - this.clients}+${this.clients}`; + } else { + badgeText = `${totalClients}`; + } + } } chrome.browserAction.setIcon({ path: path, }); + // Color is taken from Tor Browser (tor-styles.css, `purple-30`, + // with lightness changed to 81%). + chrome.browserAction.setBadgeBackgroundColor({ color: '#d79eff' }); + chrome.browserAction.setBadgeText({ text: badgeText }); }
}