From b45479a733a9fefc1aa19abdecabff07c189531d Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 28 Jun 2019 12:01:00 +0200 Subject: [PATCH] Commit network settings in separate method --- .../NetworkSettingsViewController.swift | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift b/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift index 3c426bca..a147ea18 100644 --- a/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift +++ b/Passepartout-iOS/Scenes/NetworkSettingsViewController.swift @@ -53,10 +53,10 @@ class NetworkSettingsViewController: UITableViewController { private lazy var networkChoices = ProfileNetworkChoices.with(profile: profile) - private let networkSettings = ProfileNetworkSettings() - private lazy var clientNetworkSettings = profile?.clientNetworkSettings + private let networkSettings = ProfileNetworkSettings() + // MARK: TableModelHost let model: TableModel = TableModel() @@ -124,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 @@ -220,6 +205,25 @@ class NetworkSettingsViewController: UITableViewController { log.debug("Network settings: \(networkSettings)") } + + private func commitChanges() { + 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 + } + } } // MARK: -