mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-13 03:12:08 +00:00
macOS: Tunnel edit: Clean up error handling when saving
This commit is contained in:
parent
285c21c84c
commit
808c95567a
@ -186,14 +186,25 @@ class TunnelEditViewController: NSViewController {
|
|||||||
} else {
|
} else {
|
||||||
onDemandSetting = ActivateOnDemandSetting(isActivateOnDemandEnabled: true, activateOnDemandOption: onDemandOption)
|
onDemandSetting = ActivateOnDemandSetting(isActivateOnDemandEnabled: true, activateOnDemandOption: onDemandOption)
|
||||||
}
|
}
|
||||||
if let tunnel = tunnel {
|
|
||||||
// We're modifying an existing tunnel
|
let isTunnelModifiedWithoutChangingName = (tunnel != nil && tunnel!.name == name)
|
||||||
if name != tunnel.name && tunnelsManager.tunnel(named: name) != nil {
|
guard isTunnelModifiedWithoutChangingName || tunnelsManager.tunnel(named: name) == nil else {
|
||||||
ErrorPresenter.showErrorAlert(title: tr(format: "macAlertDuplicateName (%@)", name), message: "", from: self)
|
ErrorPresenter.showErrorAlert(title: tr(format: "macAlertDuplicateName (%@)", name), message: "", from: self)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tunnelConfiguration: TunnelConfiguration
|
||||||
do {
|
do {
|
||||||
let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: textView.string, called: nameRow.value)
|
tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: textView.string, called: nameRow.value)
|
||||||
|
} catch let error as WireGuardAppError {
|
||||||
|
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||||
|
return
|
||||||
|
} catch {
|
||||||
|
fatalError()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let tunnel = tunnel {
|
||||||
|
// We're modifying an existing tunnel
|
||||||
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] error in
|
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||||
@ -202,19 +213,8 @@ class TunnelEditViewController: NSViewController {
|
|||||||
self?.dismiss(self)
|
self?.dismiss(self)
|
||||||
self?.delegate?.tunnelSaved(tunnel: tunnel)
|
self?.delegate?.tunnelSaved(tunnel: tunnel)
|
||||||
}
|
}
|
||||||
} catch let error as WireGuardAppError {
|
|
||||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
|
||||||
} catch {
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// We're creating a new tunnel
|
// 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)
|
|
||||||
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] result in
|
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] result in
|
||||||
if let error = result.error {
|
if let error = result.error {
|
||||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||||
@ -224,11 +224,6 @@ class TunnelEditViewController: NSViewController {
|
|||||||
self?.delegate?.tunnelSaved(tunnel: tunnel)
|
self?.delegate?.tunnelSaved(tunnel: tunnel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch let error as WireGuardAppError {
|
|
||||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
|
||||||
} catch {
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user