aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-24 18:35:07 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-24 18:35:11 +0530
commiteabeb8ff05efe604d8a031d2f778f490430e9a76 (patch)
tree6aec93aa24ff221d60d4b6baad63c42d0be0f848 /WireGuard/WireGuard
parentTunnelsTracker: Simplify using TunnelsManager.tunnelInOperation() (diff)
downloadwireguard-apple-eabeb8ff05efe604d8a031d2f778f490430e9a76.tar.xz
wireguard-apple-eabeb8ff05efe604d8a031d2f778f490430e9a76.zip
macOS: Select the active tunnel when showing the manage tunnels window
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift4
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift15
2 files changed, 18 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index d65814bd..7b1a9af8 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -226,6 +226,10 @@ class TunnelsManager {
return tunnels[index]
}
+ func index(of tunnel: TunnelContainer) -> Int? {
+ return tunnels.firstIndex(of: tunnel)
+ }
+
func tunnel(named tunnelName: String) -> TunnelContainer? {
return tunnels.first { $0.name == tunnelName }
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 5ae89c44..46f6bcb5 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -61,7 +61,8 @@ class TunnelsListTableViewController: NSViewController {
override func loadView() {
tableView.dataSource = self
tableView.delegate = self
- let isSelected = selectTunnel(at: 0)
+
+ let isSelected = selectTunnelInOperation() || selectTunnel(at: 0)
if !isSelected {
delegate?.tunnelsListEmpty()
}
@@ -110,6 +111,18 @@ class TunnelsListTableViewController: NSViewController {
view = containerView
}
+ override func viewWillAppear() {
+ selectTunnelInOperation()
+ }
+
+ @discardableResult
+ func selectTunnelInOperation() -> Bool {
+ if let currentTunnel = tunnelsManager.tunnelInOperation(), let indexToSelect = tunnelsManager.index(of: currentTunnel) {
+ return selectTunnel(at: indexToSelect)
+ }
+ return false
+ }
+
@objc func buttonBarClicked(sender: AnyObject?) {
guard let buttonBar = sender as? NSSegmentedControl else { return }
// We have to resort to explicitly showing the menu instead of using NSSegmentedControl.setMenu()