From 3245ef2f821fee0580f7d97c6f05223c2673e318 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 29 Apr 2019 15:52:17 +0200 Subject: service: pass global state with notification --- ui/tunnelspage.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'ui/tunnelspage.go') 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() { -- cgit v1.2.3-59-g8ed1b