diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-01-18 11:15:40 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-01-18 11:15:40 +0100 |
commit | ad81ddbf91df3d0ece62eab322dfd15e8866193b (patch) | |
tree | 4915dcfb705300d82e858829b7acd6f7e6a65c07 /systray.go | |
parent | d4245e59b480dcadbbd5df4027b50a57aff3ff3e (diff) |
[style] New assets
Diffstat (limited to 'systray.go')
-rw-r--r-- | systray.go | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "time" "0xacab.org/meskio/bitmask-systray/icon" "github.com/getlantern/systray" @@ -11,6 +12,7 @@ import ( type bmTray struct { ch chan string + waitCh chan bool mStatus *systray.MenuItem mTurnOn *systray.MenuItem mTurnOff *systray.MenuItem @@ -93,6 +95,10 @@ func (bt *bmTray) onReady() { func (bt *bmTray) changeStatus(status string) { statusStr := status + if bt.waitCh != nil { + bt.waitCh <- true + bt.waitCh = nil + } switch status { case "on": @@ -108,13 +114,15 @@ func (bt *bmTray) changeStatus(status string) { go bt.mCancel.Hide() case "starting": - systray.SetIcon(icon.Wait) + bt.waitCh = make(chan bool) + go bt.waitIcon() go bt.mTurnOn.Hide() go bt.mTurnOff.Hide() go bt.mCancel.Show() case "stopping": - systray.SetIcon(icon.Wait) + bt.waitCh = make(chan bool) + go bt.waitIcon() go bt.mTurnOn.Hide() go bt.mTurnOff.Hide() go bt.mCancel.Hide() @@ -131,3 +139,17 @@ func (bt *bmTray) changeStatus(status string) { bt.mStatus.SetTitle("VPN is " + statusStr) bt.mStatus.SetTooltip("RiseupVPN is " + statusStr) } + +func (bt *bmTray) waitIcon() { + i := 0 + icons := [][]byte{icon.Wait0, icon.Wait1, icon.Wait2, icon.Wait3} + for { + systray.SetIcon(icons[i]) + select { + case <-bt.waitCh: + return + case <-time.After(time.Millisecond * 500): + i = (i + 1) % 4 + } + } +} |