aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-09 01:17:46 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:35 +0530
commit922b6f76b21d0c2b270fbe5a4743d28977cfe02e (patch)
treeaf1ab2cb29ae82f69534c305a0b23f3ebaaac7d9 /WireGuard
parentmacOS: Update detail view after editing (diff)
downloadwireguard-apple-922b6f76b21d0c2b270fbe5a4743d28977cfe02e.tar.xz
wireguard-apple-922b6f76b21d0c2b270fbe5a4743d28977cfe02e.zip
macOS: Manage tunnels: Add empty tunnel pulldown menu implementation
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift43
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift3
2 files changed, 43 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
index 62eba17..ae95fba 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
@@ -81,8 +81,10 @@ class TunnelEditViewController: NSViewController {
fatalError("init(coder:) has not been implemented")
}
- override func loadView() {
- if let tunnel = tunnel, let tunnelConfiguration = tunnel.tunnelConfiguration {
+ func populateTextFields() {
+ if let tunnel = tunnel {
+ // Editing an existing tunnel
+ let tunnelConfiguration = tunnel.tunnelConfiguration!
nameRow.value = tunnel.name
textView.string = tunnelConfiguration.asWgQuickConfig()
publicKeyRow.value = tunnelConfiguration.interface.publicKey.base64EncodedString()
@@ -97,7 +99,21 @@ class TunnelEditViewController: NSViewController {
publicKeyRow?.value = ""
}
}
+ } else {
+ // Creating a new tunnel
+ let privateKey = Curve25519.generatePrivateKey()
+ let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey)
+ let bootstrappingText = """
+ [Interface]
+ PrivateKey = \(privateKey.base64EncodedString())
+ """
+ publicKeyRow.value = publicKey.base64EncodedString()
+ textView.string = bootstrappingText
}
+ }
+
+ override func loadView() {
+ populateTextFields()
scrollView.documentView = textView
@@ -163,6 +179,29 @@ class TunnelEditViewController: NSViewController {
} catch {
fatalError()
}
+ } else {
+ // We're creating a new tunnel
+ if tunnelsManager.tunnel(named: name) != nil {
+ ErrorPresenter.showErrorAlert(title: tr(format: "macAlertDuplicateName (%@)", name), message: "", from: self)
+ return
+ }
+ do {
+ let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: textView.string, called: nameRow.value)
+ let onDemandSetting = ActivateOnDemandSetting.defaultSetting
+ tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] result in
+ if let error = result.error {
+ ErrorPresenter.showErrorAlert(error: error, from: self)
+ } else {
+ let tunnel: TunnelContainer = result.value!
+ self?.dismiss(self)
+ self?.delegate?.tunnelSaved(tunnel: tunnel)
+ }
+ }
+ } catch let error as WireGuardAppError {
+ ErrorPresenter.showErrorAlert(error: error, from: self)
+ } catch {
+ fatalError()
+ }
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 723814e..162cf15 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -127,7 +127,8 @@ class TunnelsListTableViewController: NSViewController {
}
@objc func addEmptyTunnelClicked() {
- print("addEmptyTunnelClicked")
+ let tunnelEditVC = TunnelEditViewController(tunnelsManager: tunnelsManager, tunnel: nil)
+ presentAsSheet(tunnelEditVC)
}
@objc func importTunnelClicked() {