From ad81ddbf91df3d0ece62eab322dfd15e8866193b Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 18 Jan 2018 11:15:40 +0100 Subject: [style] New assets --- systray.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'systray.go') diff --git a/systray.go b/systray.go index 9614e7f..fa19c0f 100644 --- a/systray.go +++ b/systray.go @@ -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 + } + } +} -- cgit v1.2.3