aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui
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
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')
-rw-r--r--ui/confview.go45
-rw-r--r--ui/tray.go65
2 files changed, 69 insertions, 41 deletions
diff --git a/ui/confview.go b/ui/confview.go
index 57d0b0bf..a8e92957 100644
--- a/ui/confview.go
+++ b/ui/confview.go
@@ -420,16 +420,20 @@ func (cv *ConfView) Dispose() {
func (cv *ConfView) onToggleActiveClicked() {
cv.interfaze.toggleActive.button.SetEnabled(false)
- oldState, err := cv.tunnel.Toggle()
- if err != nil {
- if oldState == service.TunnelUnknown {
- walk.MsgBox(cv.Form(), "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError)
- } else if oldState == service.TunnelStopped {
- walk.MsgBox(cv.Form(), "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError)
- } else if oldState == service.TunnelStarted {
- walk.MsgBox(cv.Form(), "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError)
+ go func() {
+ oldState, err := cv.tunnel.Toggle()
+ if err != nil {
+ cv.Synchronize(func() {
+ if oldState == service.TunnelUnknown {
+ walk.MsgBox(cv.Form(), "Failed to determine tunnel state", err.Error(), walk.MsgBoxIconError)
+ } else if oldState == service.TunnelStopped {
+ walk.MsgBox(cv.Form(), "Failed to activate tunnel", err.Error(), walk.MsgBoxIconError)
+ } else if oldState == service.TunnelStarted {
+ walk.MsgBox(cv.Form(), "Failed to deactivate tunnel", err.Error(), walk.MsgBoxIconError)
+ }
+ })
}
- }
+ }()
}
func (cv *ConfView) onTunnelChanged(tunnel *service.Tunnel, state service.TunnelState, globalState service.TunnelState, err error) {
@@ -448,14 +452,27 @@ func (cv *ConfView) SetTunnel(tunnel *service.Tunnel) {
var config conf.Config
var state service.TunnelState
if tunnel != nil {
- if state, _ = tunnel.State(); state == service.TunnelStarted {
- config, _ = tunnel.RuntimeConfig()
- }
- if config.Name == "" {
- config, _ = tunnel.StoredConfig()
+ title := "Interface: " + tunnel.Name
+ if title != cv.name.Title() {
+ //TODO: display some sort of loading screen here!
}
+ go func() {
+ if state, _ = tunnel.State(); state == service.TunnelStarted {
+ config, _ = tunnel.RuntimeConfig()
+ }
+ if config.Name == "" {
+ config, _ = tunnel.StoredConfig()
+ }
+ cv.Synchronize(func() {
+ cv.setTunnel(tunnel, &config, state)
+ })
+ }()
+ } else {
+ cv.setTunnel(tunnel, &config, state)
}
+}
+func (cv *ConfView) setTunnel(tunnel *service.Tunnel, config *conf.Config, state service.TunnelState) {
cv.name.SetVisible(tunnel != nil)
hasSuspended := false
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 {