diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 21:10:38 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 21:10:38 +0200 |
commit | 59e5a54bc4d5808afc918c7f0de81fe59c6f8da8 (patch) | |
tree | e2316076dfb54fd7e610c3b2d1156dd7c1552a92 | |
parent | ui: rework tunnel adding logic and fix bugs (diff) | |
download | wireguard-windows-59e5a54bc4d5808afc918c7f0de81fe59c6f8da8.tar.xz wireguard-windows-59e5a54bc4d5808afc918c7f0de81fe59c6f8da8.zip |
ui: show first active tunnels on window popup
-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 + } + } + }() +} |