Count the number of clients the webext has served

This commit is contained in:
Arlo Breault 2019-06-19 16:02:12 -04:00
parent 91255463c6
commit 85625e19f9
4 changed files with 21 additions and 3 deletions

View file

@ -51,13 +51,26 @@ class DebugUI extends UI
class WebExtUI extends UI
port: null
stats: null
constructor: ->
@initStats()
chrome.runtime.onConnect.addListener @onConnect
initStats: ->
@stats = [0]
setInterval (() =>
@stats.unshift 0
@stats.splice 24
@postActive()
), 60 * 60 * 1000
postActive: ->
@port?.postMessage
active: @active
total: @stats.reduce ((t, c) ->
t + c
), 0
onConnect: (port) =>
@port = port
@ -69,6 +82,7 @@ class WebExtUI extends UI
setActive: (connected) ->
super connected
if connected then @stats[0] += 1
@postActive()
chrome.browserAction.setIcon
path: