diff options
-rw-r--r-- | ui/tray.go | 12 | ||||
-rw-r--r-- | ui/tunnelsview.go | 19 |
2 files changed, 29 insertions, 2 deletions
@@ -52,7 +52,7 @@ func (tray *Tray) setup() error { tray.MouseDown().Attach(func(x, y int, button walk.MouseButton) { if button == walk.LeftButton { - tray.mtw.Show() + tray.onManageTunnels() } }) @@ -68,7 +68,7 @@ func (tray *Tray) setup() error { {label: "Networks: None", hidden: true}, {separator: true}, {separator: true}, - {label: "&Manage tunnels...", handler: tray.mtw.Show, enabled: true}, + {label: "&Manage tunnels...", handler: tray.onManageTunnels, enabled: true}, {label: "&Import tunnel(s) from file...", handler: tray.mtw.tunnelsPage.onImport, enabled: true}, {separator: true}, {label: "&About WireGuard", handler: func() { onAbout(tray.mtw) }, enabled: true}, @@ -297,3 +297,11 @@ func (tray *Tray) UpdateFound() { tray.ContextMenu().Actions().Insert(tray.ContextMenu().Actions().Len()-2, action) tray.ShowWarning("WireGuard Update Available", "An update to WireGuard is now available. You are advised to update as soon as possible.") } + +func (tray *Tray) onManageTunnels() { + if !tray.mtw.Visible() { + tray.mtw.tunnelsPage.tunnelsView.SelectFirstActiveTunnel() + tray.mtw.tabs.SetCurrentIndex(0) + } + tray.mtw.Show() +} diff --git a/ui/tunnelsview.go b/ui/tunnelsview.go index 15dc22ca..26099c2c 100644 --- a/ui/tunnelsview.go +++ b/ui/tunnelsview.go @@ -207,3 +207,22 @@ func (tv *TunnelsView) selectTunnel(tunnelName string) { } } } + +func (tv *TunnelsView) SelectFirstActiveTunnel() { + tunnels := make([]service.Tunnel, len(tv.model.tunnels)) + copy(tunnels, tv.model.tunnels) + go func() { + for _, tunnel := range tunnels { + state, err := tunnel.State() + if err != nil { + continue + } + if state == service.TunnelStarting || state == service.TunnelStarted { + tv.Synchronize(func() { + tv.selectTunnel(tunnel.Name) + }) + return + } + } + }() +} |