diff options
author | Roopesh Chander <roop@roopc.net> | 2019-01-08 18:58:40 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-01-14 14:52:34 +0530 |
commit | b0612df990bd9afdb3e8d39e9ca06fba72b330b1 (patch) | |
tree | 427dcdb64e0468ad6714b1c45654dbfdeb3193cd /WireGuard | |
parent | macOS: Refactor config file parsing (diff) | |
download | wireguard-apple-b0612df990bd9afdb3e8d39e9ca06fba72b330b1.tar.xz wireguard-apple-b0612df990bd9afdb3e8d39e9ca06fba72b330b1.zip |
macOS: Edit view: Validate and save
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r-- | WireGuard/WireGuard/Base.lproj/Localizable.strings | 3 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift | 28 |
2 files changed, 30 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings index 897d13d..e2a7295 100644 --- a/WireGuard/WireGuard/Base.lproj/Localizable.strings +++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings @@ -257,6 +257,9 @@ "macEditDiscard" = "Discard"; "macEditSave" = "Save"; +"macAlertNameIsEmpty" = "Name is required"; +"macAlertDuplicateName (%@)" = "Another tunnel already exists with the name '%@'."; + "macAlertInvalidLine (%@)" = "Invalid line: '%@'."; "macAlertNoInterface" = "Configuration must have an 'Interface' section."; diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift index 47f488c..42cc681 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift @@ -116,7 +116,33 @@ class TunnelEditViewController: NSViewController { } @objc func saveButtonClicked() { - print("saveButtonClicked") + let name = nameRow.value + guard !name.isEmpty else { + ErrorPresenter.showErrorAlert(title: tr("macAlertNameIsEmpty"), message: "", from: self) + return + } + if let tunnel = tunnel { + // We're modifying an existing tunnel + if name != tunnel.name && 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, ignoreUnrecognizedKeys: false) + let onDemandSetting = ActivateOnDemandSetting.defaultSetting + tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] error in + if let error = error { + ErrorPresenter.showErrorAlert(error: error, from: self) + return + } + self?.dismiss(self) + } + } catch let error as WireGuardAppError { + ErrorPresenter.showErrorAlert(error: error, from: self) + } catch { + fatalError() + } + } } @objc func discardButtonClicked() { |