aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-09 02:41:42 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:35 +0530
commit8980b5a5243e6e695129fd8ac429098eb8c5ee3b (patch)
treeb5aa162a7466829f8fa1cd63d4538392cb0e1195 /WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
parentmacOS: Handle errors from TunnelsManager.create() (diff)
downloadwireguard-apple-8980b5a5243e6e695129fd8ac429098eb8c5ee3b.tar.xz
wireguard-apple-8980b5a5243e6e695129fd8ac429098eb8c5ee3b.zip
macOS: Ensure a tunnel is selected when '-' is clicked
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift5
1 files changed, 3 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 709ec8ec..e6b72ca3 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -138,6 +138,7 @@ class TunnelsListTableViewController: NSViewController {
@objc func removeTunnelClicked() {
guard let window = view.window else { return }
let selectedTunnelIndex = tableView.selectedRow
+ guard selectedTunnelIndex >= 0 && selectedTunnelIndex < tunnelsManager.numberOfTunnels() else { return }
let selectedTunnel = tunnelsManager.tunnel(at: selectedTunnelIndex)
let alert = NSAlert()
alert.messageText = tr(format: "macDeleteTunnelConfirmationAlertMessage (%@)", selectedTunnel.name)
@@ -149,13 +150,13 @@ class TunnelsListTableViewController: NSViewController {
self?.buttonBar.setEnabled(false, forSegment: 1)
self?.tunnelsManager.remove(tunnel: selectedTunnel) { [weak self] error in
guard let self = self else { return }
- self.buttonBar.setEnabled(true, forSegment: 1)
+ defer { self.buttonBar.setEnabled(true, forSegment: 1) }
if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self)
return
}
let tunnelIndex = min(selectedTunnelIndex, self.tunnelsManager.numberOfTunnels() - 1)
- if tunnelIndex > 0 {
+ if tunnelIndex >= 0 {
self.selectTunnel(at: tunnelIndex)
}
}