aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/tray.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-29 16:07:16 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-29 16:07:16 +0200
commit98b226b737693690306b2d74190118a501d4457f (patch)
tree81ec223697bff32606e1c7427b452faf8844ab0a /ui/tray.go
parentservice: pass global state with notification (diff)
downloadwireguard-windows-98b226b737693690306b2d74190118a501d4457f.tar.xz
wireguard-windows-98b226b737693690306b2d74190118a501d4457f.zip
ui: make IPC calls in go routines
Diffstat (limited to 'ui/tray.go')
-rw-r--r--ui/tray.go65
1 files changed, 38 insertions, 27 deletions
diff --git a/ui/tray.go b/ui/tray.go
index b2a6446b..2f48d812 100644
--- a/ui/tray.go
+++ b/ui/tray.go
@@ -139,19 +139,22 @@ func (tray *Tray) addTunnelAction(tunnel *service.Tunnel) {
tclosure := *tunnel
tunnelAction.Triggered().Attach(func() {
tunnelAction.SetChecked(!tunnelAction.Checked())
- oldState, err := tclosure.Toggle()
- if err != nil {
- tray.mtw.Show()
- //TODO: select tunnel that we're showing the error for in mtw
- if oldState == service.TunnelUnknown {
- walk.MsgBox(tray.mtw, "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError)
- } else if oldState == service.TunnelStopped {
- walk.MsgBox(tray.mtw, "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError)
- } else if oldState == service.TunnelStarted {
- walk.MsgBox(tray.mtw, "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError)
+ go func() {
+ oldState, err := tclosure.Toggle()
+ if err != nil {
+ tray.mtw.Synchronize(func() {
+ tray.mtw.Show()
+ //TODO: select tunnel that we're showing the error for in mtw
+ if oldState == service.TunnelUnknown {
+ walk.MsgBox(tray.mtw, "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError)
+ } else if oldState == service.TunnelStopped {
+ walk.MsgBox(tray.mtw, "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError)
+ } else if oldState == service.TunnelStarted {
+ walk.MsgBox(tray.mtw, "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError)
+ }
+ })
}
- return
- }
+ }()
})
tray.tunnels[tunnel.Name] = tunnelAction
@@ -174,11 +177,15 @@ func (tray *Tray) addTunnelAction(tunnel *service.Tunnel) {
tray.ContextMenu().Actions().Insert(trayTunnelActionsOffset+idx, tunnelAction)
- state, err := tunnel.State()
- if err != nil {
- return
- }
- tray.SetTunnelState(tunnel, state, false)
+ go func() {
+ state, err := tunnel.State()
+ if err != nil {
+ return
+ }
+ tray.mtw.Synchronize(func() {
+ tray.SetTunnelState(tunnel, state, false)
+ })
+ }()
}
func (tray *Tray) removeTunnelAction(tunnelName string) {
@@ -248,18 +255,22 @@ func (tray *Tray) SetTunnelState(tunnel *service.Tunnel, state service.TunnelSta
switch state {
case service.TunnelStarted:
activeCIDRsAction.SetText("")
- config, err := tunnel.RuntimeConfig()
- if err == nil {
- var sb strings.Builder
- for i, addr := range config.Interface.Addresses {
- if i > 0 {
- sb.WriteString(", ")
+ go func() {
+ config, err := tunnel.RuntimeConfig()
+ if err == nil {
+ var sb strings.Builder
+ for i, addr := range config.Interface.Addresses {
+ if i > 0 {
+ sb.WriteString(", ")
+ }
+
+ sb.WriteString(addr.String())
}
-
- sb.WriteString(addr.String())
+ tray.mtw.Synchronize(func() {
+ activeCIDRsAction.SetText(fmt.Sprintf("Networks: %s", sb.String()))
+ })
}
- activeCIDRsAction.SetText(fmt.Sprintf("Networks: %s", sb.String()))
- }
+ }()
tunnelAction.SetEnabled(true)
tunnelAction.SetChecked(true)
if !wasChecked && showNotifications {