diff options
author | Roopesh Chander <roop@roopc.net> | 2018-11-05 22:55:09 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-11-05 22:55:09 +0530 |
commit | f102051e22795d4bbfeb79024300efb674ff9d31 (patch) | |
tree | bdfbe9b3ac57fcc14eac672882d5f91655f743d9 | |
parent | global: convert to Swift 4.2 (diff) | |
download | wireguard-apple-f102051e22795d4bbfeb79024300efb674ff9d31.tar.xz wireguard-apple-f102051e22795d4bbfeb79024300efb674ff9d31.zip |
Tunnel view model: No need to save if we already have a validated configuration object
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r-- | WireGuard/WireGuard/UI/TunnelViewModel.swift | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 6fa13b4..da292c4 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -96,6 +96,10 @@ class TunnelViewModel { } func save() -> SaveResult<InterfaceConfiguration> { + if let validatedConfiguration = validatedConfiguration { + // It's already validated and saved + return .saved(validatedConfiguration) + } fieldsWithError.removeAll() guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else { fieldsWithError.insert(.name) @@ -234,6 +238,10 @@ class TunnelViewModel { } func save() -> SaveResult<PeerConfiguration> { + if let validatedConfiguration = validatedConfiguration { + // It's already validated and saved + return .saved(validatedConfiguration) + } fieldsWithError.removeAll() guard let publicKeyString = scratchpad[.publicKey] else { fieldsWithError.insert(.publicKey) |