From 2e362bf5532479447b8c506bb0b49f2f4a0e7772 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 22 Jun 2019 09:34:43 +0200 Subject: [PATCH] Reuse Core extensions - NetworkChoice.choices() - OpenVPN.* available options - ConnectionProfile.clientNetworkSettings --- .../Scenes/ConfigurationViewController.swift | 8 ++++---- .../NetworkSettingsViewController.swift | 20 ++++--------------- Passepartout.xcodeproj/project.pbxproj | 4 ++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Passepartout-iOS/Scenes/ConfigurationViewController.swift b/Passepartout-iOS/Scenes/ConfigurationViewController.swift index 5559b4b4..5f08e86a 100644 --- a/Passepartout-iOS/Scenes/ConfigurationViewController.swift +++ b/Passepartout-iOS/Scenes/ConfigurationViewController.swift @@ -315,7 +315,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat case .cipher: let vc = OptionViewController() vc.title = settingCell?.leftText - vc.options = [.aes128cbc, .aes192cbc, .aes256cbc, .aes128gcm, .aes192gcm, .aes256gcm] + vc.options = OpenVPN.Cipher.available vc.selectedOption = configuration.cipher vc.descriptionBlock = { $0.description } vc.selectionBlock = { [weak self] in @@ -327,7 +327,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat case .digest: let vc = OptionViewController() vc.title = settingCell?.leftText - vc.options = [.sha1, .sha224, .sha256, .sha384, .sha512] + vc.options = OpenVPN.Digest.available vc.selectedOption = configuration.digest vc.descriptionBlock = { $0.description } vc.selectionBlock = { [weak self] in @@ -339,7 +339,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat case .compressionFraming: let vc = OptionViewController() vc.title = settingCell?.leftText - vc.options = [.disabled, .compLZO, .compress] + vc.options = OpenVPN.CompressionFraming.available vc.selectedOption = configuration.compressionFraming ?? .disabled vc.descriptionBlock = { $0.cellDescription } vc.selectionBlock = { [weak self] in @@ -358,7 +358,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat let vc = OptionViewController() vc.title = settingCell?.leftText - vc.options = [.disabled, .LZO] + vc.options = OpenVPN.CompressionAlgorithm.available vc.selectedOption = configuration.compressionAlgorithm ?? .disabled vc.descriptionBlock = { $0.cellDescription } vc.selectionBlock = { [weak self] in diff --git a/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift b/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift index 15961bce..30f18a8d 100644 --- a/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift +++ b/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift @@ -66,19 +66,7 @@ class NetworkSettingsViewController: UITableViewController { private let networkSettings = ProfileNetworkSettings() - private lazy var clientNetworkSettings: ProfileNetworkSettings? = { - guard let hostProfile = profile as? HostConnectionProfile else { - return nil - } - return ProfileNetworkSettings(from: hostProfile.parameters.sessionConfiguration) - }() - - private var choices: [NetworkChoice] { - guard let _ = clientNetworkSettings else { - return [.server, .manual] - } - return [.client, .server, .manual] - } + private lazy var clientNetworkSettings = profile?.clientNetworkSettings // MARK: TableModelHost @@ -430,7 +418,7 @@ extension NetworkSettingsViewController { case .gateway: let vc = OptionViewController() vc.title = (cell as? SettingTableViewCell)?.leftText - vc.options = choices + vc.options = NetworkChoice.choices(for: profile) vc.descriptionBlock = { $0.description } vc.selectedOption = networkChoices.gateway @@ -443,7 +431,7 @@ extension NetworkSettingsViewController { case .dns: let vc = OptionViewController() vc.title = (cell as? SettingTableViewCell)?.leftText - vc.options = choices + vc.options = NetworkChoice.choices(for: profile) vc.descriptionBlock = { $0.description } vc.selectedOption = networkChoices.dns @@ -456,7 +444,7 @@ extension NetworkSettingsViewController { case .proxy: let vc = OptionViewController() vc.title = (cell as? SettingTableViewCell)?.leftText - vc.options = choices + vc.options = NetworkChoice.choices(for: profile) vc.descriptionBlock = { $0.description } vc.selectedOption = networkChoices.proxy diff --git a/Passepartout.xcodeproj/project.pbxproj b/Passepartout.xcodeproj/project.pbxproj index 2bff6ba7..4e6db6d7 100644 --- a/Passepartout.xcodeproj/project.pbxproj +++ b/Passepartout.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ 0E45E6E022BD793800F19312 /* App.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E45E6E222BD793800F19312 /* App.strings */; }; 0E45E6E422BD799700F19312 /* SwiftGen+Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E45E6E322BD799700F19312 /* SwiftGen+Strings.swift */; }; 0E45E6FA22BD8FC500F19312 /* Core.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E3CAF98229AAE760008E5C8 /* Core.strings */; }; + 0E45E71022BE108100F19312 /* OpenVPNOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */; }; 0E4C9CBB20DCF0D600A0C59C /* DestructiveTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4C9CBA20DCF0D600A0C59C /* DestructiveTableViewCell.swift */; }; 0E4FD7F120D58618002221FF /* Macros.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4FD7F020D58618002221FF /* Macros.swift */; }; 0E533B162258E03B00EF94FC /* PoolGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E533B152258E03B00EF94FC /* PoolGroup.swift */; }; @@ -203,6 +204,7 @@ 0E45E6F722BD898800F19312 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/App.strings; sourceTree = ""; }; 0E45E6F822BD898A00F19312 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/App.strings; sourceTree = ""; }; 0E45E6F922BD898B00F19312 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/App.strings; sourceTree = ""; }; + 0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenVPNOptions.swift; sourceTree = ""; }; 0E4C9CB820DB9BC600A0C59C /* TrustedNetworks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustedNetworks.swift; sourceTree = ""; }; 0E4C9CBA20DCF0D600A0C59C /* DestructiveTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestructiveTableViewCell.swift; sourceTree = ""; }; 0E4FD7DD20D3E49A002221FF /* StandardVPNProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardVPNProvider.swift; sourceTree = ""; }; @@ -502,6 +504,7 @@ 0ECEB109224FECEA00E9E551 /* DataUnit.swift */, 0EC7F20420E24308004EA58E /* DebugLog.swift */, 0ED38AE621404F100004D387 /* EndpointDataSource.swift */, + 0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */, 0E89DFC4213DF7AE00741BA1 /* Preferences.swift */, 0EFB901722764689006405E4 /* ProfileNetworkSettings.swift */, 0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */, @@ -942,6 +945,7 @@ 0E3152C2223FA04800F61841 /* MockVPNProvider.swift in Sources */, 0E533B162258E03B00EF94FC /* PoolGroup.swift in Sources */, 0E3152D2223FA05400F61841 /* DebugLog.swift in Sources */, + 0E45E71022BE108100F19312 /* OpenVPNOptions.swift in Sources */, 0E3152C4223FA04800F61841 /* VPN.swift in Sources */, 0E3152C6223FA04800F61841 /* VPNProvider.swift in Sources */, 0E3152DA223FA05800F61841 /* PlaceholderConnectionProfile.swift in Sources */,