aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/tray.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-29 15:52:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-29 15:52:17 +0200
commit3245ef2f821fee0580f7d97c6f05223c2673e318 (patch)
treea37424f17b611c6d5d04da9fceb4a756dadf52ab /ui/tray.go
parentui: account for IPC failures in UI initialization (diff)
downloadwireguard-windows-3245ef2f821fee0580f7d97c6f05223c2673e318.tar.xz
wireguard-windows-3245ef2f821fee0580f7d97c6f05223c2673e318.zip
service: pass global state with notification
Diffstat (limited to '')
-rw-r--r--ui/tray.go21
1 files changed, 8 insertions, 13 deletions
diff --git a/ui/tray.go b/ui/tray.go
index ca839a83..b2a6446b 100644
--- a/ui/tray.go
+++ b/ui/tray.go
@@ -92,7 +92,8 @@ func (tray *Tray) setup() error {
tray.tunnelChangedCB = service.IPCClientRegisterTunnelChange(tray.onTunnelChange)
tray.tunnelsChangedCB = service.IPCClientRegisterTunnelsChange(tray.onTunnelsChange)
tray.onTunnelsChange()
- tray.updateGlobalState()
+ globalState, _ := service.IPCClientGlobalState()
+ tray.updateGlobalState(globalState)
return nil
}
@@ -185,22 +186,18 @@ func (tray *Tray) removeTunnelAction(tunnelName string) {
delete(tray.tunnels, tunnelName)
}
-func (tray *Tray) onTunnelChange(tunnel *service.Tunnel, state service.TunnelState, err error) {
+func (tray *Tray) onTunnelChange(tunnel *service.Tunnel, state service.TunnelState, globalState service.TunnelState, err error) {
tray.mtw.Synchronize(func() {
tray.SetTunnelState(tunnel, state, err == nil)
+ tray.updateGlobalState(globalState)
if !tray.mtw.Visible() && err != nil {
tray.ShowError("WireGuard Tunnel Error", err.Error())
}
})
}
-func (tray *Tray) updateGlobalState() {
- state, err := service.IPCClientGlobalState()
- if err != nil {
- return
- }
-
- if icon, err := iconProvider.IconWithOverlayForState(state); err == nil {
+func (tray *Tray) updateGlobalState(globalState service.TunnelState) {
+ if icon, err := iconProvider.IconWithOverlayForState(globalState); err == nil {
tray.SetIcon(icon)
}
@@ -215,14 +212,14 @@ func (tray *Tray) updateGlobalState() {
}
}
- switch state {
+ switch globalState {
case service.TunnelStarting:
statusAction.SetText("Status: Activating")
setTunnelActionsEnabled(false)
tray.SetToolTip("WireGuard: Activating...")
case service.TunnelStarted:
- activeCIDRsAction.SetVisible(err == nil)
+ activeCIDRsAction.SetVisible(true)
statusAction.SetText("Status: Active")
setTunnelActionsEnabled(true)
tray.SetToolTip("WireGuard: Activated")
@@ -275,8 +272,6 @@ func (tray *Tray) SetTunnelState(tunnel *service.Tunnel, state service.TunnelSta
tray.ShowInfo("WireGuard Deactivated", fmt.Sprintf("The %s tunnel has been deactivated.", tunnel.Name))
}
}
-
- tray.updateGlobalState()
}
func (tray *Tray) UpdateFound() {