Merge branch 'refactor-to-core'

This commit is contained in:
Davide De Rosa 2019-07-04 10:13:09 +02:00
commit 64e51c663b
3 changed files with 23 additions and 44 deletions

View File

@ -48,25 +48,14 @@ private struct Offsets {
static let proxyBypass = 2
}
// FIXME: init networkSettings with HOST profile.sessionConfiguration
// FIXME: omit "Client" for PROVIDER
class NetworkSettingsViewController: UITableViewController {
var profile: ConnectionProfile?
private lazy var networkChoices: ProfileNetworkChoices = {
if let choices = profile?.networkChoices {
return choices
}
if let _ = profile as? ProviderConnectionProfile {
return ProfileNetworkChoices(choice: .server)
}
return ProfileNetworkChoices(choice: .client)
}()
private lazy var networkChoices = ProfileNetworkChoices.with(profile: profile)
private lazy var clientNetworkSettings = profile?.clientNetworkSettings
private let networkSettings = ProfileNetworkSettings()
private lazy var clientNetworkSettings = profile?.clientNetworkSettings
// MARK: TableModelHost
@ -135,23 +124,8 @@ class NetworkSettingsViewController: UITableViewController {
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
profile?.networkChoices = networkChoices
if networkChoices.gateway == .manual {
let settings = profile?.manualNetworkSettings ?? ProfileNetworkSettings()
settings.copyGateway(from: networkSettings)
profile?.manualNetworkSettings = settings
}
if networkChoices.dns == .manual {
let settings = profile?.manualNetworkSettings ?? ProfileNetworkSettings()
settings.copyDNS(from: networkSettings)
profile?.manualNetworkSettings = settings
}
if networkChoices.proxy == .manual {
let settings = profile?.manualNetworkSettings ?? ProfileNetworkSettings()
settings.copyProxy(from: networkSettings)
profile?.manualNetworkSettings = settings
}
commitChanges()
}
// MARK: Actions
@ -231,6 +205,21 @@ class NetworkSettingsViewController: UITableViewController {
log.debug("Network settings: \(networkSettings)")
}
private func commitChanges() {
let settings = profile?.manualNetworkSettings ?? ProfileNetworkSettings()
profile?.networkChoices = networkChoices
if networkChoices.gateway == .manual {
settings.copyGateway(from: networkSettings)
}
if networkChoices.dns == .manual {
settings.copyDNS(from: networkSettings)
}
if networkChoices.proxy == .manual {
settings.copyProxy(from: networkSettings)
}
profile?.manualNetworkSettings = settings
}
}
// MARK: -

View File

@ -183,16 +183,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
}
private func addNewProvider() {
var names = Set(InfrastructureFactory.shared.allNames)
var createdNames: [Infrastructure.Name] = []
providers.forEach {
guard let name = Infrastructure.Name(rawValue: $0) else {
return
}
createdNames.append(name)
}
names.formSymmetricDifference(createdNames)
let names = service.availableProviderNames()
guard !names.isEmpty else {
let alert = Macros.alert(
L10n.Core.Organizer.Sections.Providers.header,
@ -202,8 +193,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
present(alert, animated: true, completion: nil)
return
}
availableProviderNames = names.sorted()
availableProviderNames = names
perform(segue: StoryboardSegue.Organizer.addProviderSegueIdentifier)
}

@ -1 +1 @@
Subproject commit 2d5f1f6f0d4d8d8353543da547d6b531beab1894
Subproject commit 7f4dd3c8cd031ebe536665871f5e76b15d36287e