diff options
Diffstat (limited to '')
-rw-r--r-- | ui/confview.go | 45 | ||||
-rw-r--r-- | ui/tray.go | 65 |
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 @@ -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 { |