mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-01 05:22:10 +00:00
macOS: Edit view: Validate and save
This commit is contained in:
parent
309d06217f
commit
3830499ac1
@ -257,6 +257,9 @@
|
|||||||
"macEditDiscard" = "Discard";
|
"macEditDiscard" = "Discard";
|
||||||
"macEditSave" = "Save";
|
"macEditSave" = "Save";
|
||||||
|
|
||||||
|
"macAlertNameIsEmpty" = "Name is required";
|
||||||
|
"macAlertDuplicateName (%@)" = "Another tunnel already exists with the name '%@'.";
|
||||||
|
|
||||||
"macAlertInvalidLine (%@)" = "Invalid line: '%@'.";
|
"macAlertInvalidLine (%@)" = "Invalid line: '%@'.";
|
||||||
|
|
||||||
"macAlertNoInterface" = "Configuration must have an 'Interface' section.";
|
"macAlertNoInterface" = "Configuration must have an 'Interface' section.";
|
||||||
|
@ -116,7 +116,33 @@ class TunnelEditViewController: NSViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func saveButtonClicked() {
|
@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() {
|
@objc func discardButtonClicked() {
|
||||||
|
Loading…
Reference in New Issue
Block a user