From 63e185aa230d1134d8be21fbde54458cdec4cef7 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 8 Apr 2019 16:12:36 +0200 Subject: ui: synchronize calls from other goroutines into walk Signed-off-by: Alexander Neumann --- ui/ui.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/ui.go b/ui/ui.go index 4acd4a76..7b9a8ce0 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -52,6 +52,13 @@ func RunUI() { defer tray.Dispose() // Bind to updates + setTunnelState := func(tunnel *service.Tunnel, state service.TunnelState, showNotifications bool) { + mtw.Synchronize(func() { + mtw.SetTunnelState(tunnel, state) + tray.SetTunnelStateWithNotification(tunnel, state, showNotifications) + }) + } + service.IPCClientRegisterTunnelChange(func(tunnel *service.Tunnel, state service.TunnelState, err error) { if err == nil { return @@ -66,12 +73,8 @@ func RunUI() { } else { tray.ShowError("WireGuard Tunnel Error", err.Error()) } - }) - service.IPCClientRegisterTunnelChange(func(tunnel *service.Tunnel, state service.TunnelState, err error) { - tray.SetTunnelStateWithNotification(tunnel, state, err == nil) - }) - service.IPCClientRegisterTunnelChange(func(tunnel *service.Tunnel, state service.TunnelState, err error) { - mtw.SetTunnelState(tunnel, state) + + setTunnelState(tunnel, state, err == nil) }) // Fetch current state @@ -85,8 +88,7 @@ func RunUI() { if err != nil { continue } - tray.SetTunnelStateWithNotification(&tunnel, state, false) - mtw.SetTunnelState(&tunnel, state) + setTunnelState(&tunnel, state, false) } }() -- cgit v1.2.3-59-g8ed1b