diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 15:52:17 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 15:52:17 +0200 |
commit | 5996e84c044aa6b9bcfedd694fb5f297629c56e8 (patch) | |
tree | a37424f17b611c6d5d04da9fceb4a756dadf52ab /ui/tunnelspage.go | |
parent | ui: account for IPC failures in UI initialization (diff) | |
download | wireguard-windows-5996e84c044aa6b9bcfedd694fb5f297629c56e8.tar.xz wireguard-windows-5996e84c044aa6b9bcfedd694fb5f297629c56e8.zip |
service: pass global state with notification
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/tunnelspage.go')
-rw-r--r-- | ui/tunnelspage.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index 469ecdeb..5df74d05 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -265,17 +265,25 @@ func (tp *TunnelsPage) deleteTunnel(tunnel *service.Tunnel) { // Handlers func (tp *TunnelsPage) onTunnelsViewItemActivated() { - oldState, err := tp.tunnelsView.CurrentTunnel().Toggle() - if err != nil { - if oldState == service.TunnelUnknown { - walk.MsgBox(tp.Form(), "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError) - } else if oldState == service.TunnelStopped { - walk.MsgBox(tp.Form(), "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError) - } else if oldState == service.TunnelStarted { - walk.MsgBox(tp.Form(), "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError) + go func() { + globalState, err := service.IPCClientGlobalState() + if err != nil || (globalState != service.TunnelStarted && globalState != service.TunnelStopped) { + return } - return - } + oldState, err := tp.tunnelsView.CurrentTunnel().Toggle() + if err != nil { + tp.Synchronize(func() { + if oldState == service.TunnelUnknown { + walk.MsgBox(tp.Form(), "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError) + } else if oldState == service.TunnelStopped { + walk.MsgBox(tp.Form(), "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError) + } else if oldState == service.TunnelStarted { + walk.MsgBox(tp.Form(), "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError) + } + }) + return + } + }() } func (tp *TunnelsPage) onEditTunnel() { |