aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-05 18:24:45 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:33 +0530
commitf3c29042418942f9e07281aefbc67360ebc4366f (patch)
tree14eda4b4b07dee8eb75b47afc3f64b850055458f /WireGuard/WireGuard/UI/macOS
parentmacOS: Present tunnel activation errors from the window when possible (diff)
downloadwireguard-apple-f3c29042418942f9e07281aefbc67360ebc4366f.tar.xz
wireguard-apple-f3c29042418942f9e07281aefbc67360ebc4366f.zip
macOS: Manage tunnels: Handle the case when there are no tunnels
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift5
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift53
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift17
3 files changed, 65 insertions, 10 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
index c951b45..1b1dc73 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
@@ -82,7 +82,8 @@ extension ManageTunnelsRootViewController: TunnelsListTableViewControllerDelegat
setTunnelDetailContentVC(tunnelDetailVC)
}
- func tunnelListEmpty() {
- // TODO
+ func tunnelsListEmpty() {
+ let noTunnelsVC = NoTunnelsDetailViewController(tunnelsManager: tunnelsManager)
+ setTunnelDetailContentVC(noTunnelsVC)
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
new file mode 100644
index 0000000..059403a
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class NoTunnelsDetailViewController: NSViewController {
+
+ let tunnelsManager: TunnelsManager
+
+ let importButton: NSButton = {
+ let button = NSButton()
+ button.title = tr("macButtonImportTunnels")
+ button.setButtonType(.momentaryPushIn)
+ button.bezelStyle = .rounded
+ return button
+ }()
+
+ init(tunnelsManager: TunnelsManager) {
+ self.tunnelsManager = tunnelsManager
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func loadView() {
+ let view = NSView()
+
+ importButton.target = self
+ importButton.action = #selector(importTunnelClicked)
+
+ view.addSubview(importButton)
+ importButton.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ importButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
+ importButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
+ ])
+ self.view = view
+ }
+
+ @objc func importTunnelClicked() {
+ guard let window = view.window else { return }
+ let openPanel = NSOpenPanel()
+ openPanel.allowedFileTypes = ["conf", "zip"]
+ openPanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
+ guard let tunnelsManager = tunnelsManager else { return }
+ guard response == .OK else { return }
+ guard let url = openPanel.url else { return }
+ TunnelImporter.importFromFile(url: url, into: tunnelsManager, sourceVC: nil, errorPresenterType: ErrorPresenter.self)
+ }
+ }
+}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 643529c..dff583a 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -5,7 +5,7 @@ import Cocoa
protocol TunnelsListTableViewControllerDelegate: class {
func tunnelSelected(tunnel: TunnelContainer)
- func tunnelListEmpty()
+ func tunnelsListEmpty()
}
class TunnelsListTableViewController: NSViewController {
@@ -61,7 +61,10 @@ class TunnelsListTableViewController: NSViewController {
override func loadView() {
tableView.dataSource = self
tableView.delegate = self
- selectTunnel(at: 0)
+ let isSelected = selectTunnel(at: 0)
+ if !isSelected {
+ delegate?.tunnelsListEmpty()
+ }
let scrollView = NSScrollView()
scrollView.hasVerticalScroller = true
@@ -246,6 +249,9 @@ extension TunnelsListTableViewController {
func tunnelRemoved(at index: Int) {
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
+ if tunnelsManager.numberOfTunnels() == 0 {
+ delegate?.tunnelsListEmpty()
+ }
}
}
@@ -263,12 +269,7 @@ extension TunnelsListTableViewController: NSTableViewDelegate {
}
func tableViewSelectionDidChange(_ notification: Notification) {
- guard tableView.selectedRow >= 0 else {
- if tunnelsManager.numberOfTunnels() == 0 {
- delegate?.tunnelListEmpty()
- }
- return
- }
+ guard tableView.selectedRow >= 0 else { return }
let selectedTunnel = tunnelsManager.tunnel(at: tableView.selectedRow)
delegate?.tunnelSelected(tunnel: selectedTunnel)
}