on-demand: Remove ActivateOnDemandSetting type
The ActivateOnDemandOption type shall be used instead Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
d9bdc61fb9
commit
062b4d4b16
@@ -49,18 +49,10 @@ class ActivateOnDemandViewModel {
|
||||
}
|
||||
|
||||
extension ActivateOnDemandViewModel {
|
||||
convenience init(setting: ActivateOnDemandSetting) {
|
||||
if setting.isActivateOnDemandEnabled {
|
||||
self.init(option: setting.activateOnDemandOption)
|
||||
} else {
|
||||
self.init(option: .none)
|
||||
}
|
||||
}
|
||||
|
||||
convenience init(option: ActivateOnDemandOption) {
|
||||
self.init()
|
||||
switch option {
|
||||
case .none:
|
||||
case .off:
|
||||
break
|
||||
case .wiFiInterfaceOnly(let onDemandSSIDOption):
|
||||
isWiFiInterfaceEnabled = true
|
||||
@@ -77,7 +69,7 @@ extension ActivateOnDemandViewModel {
|
||||
func toOnDemandOption() -> ActivateOnDemandOption {
|
||||
switch (isWiFiInterfaceEnabled, isNonWiFiInterfaceEnabled) {
|
||||
case (false, false):
|
||||
return .none
|
||||
return .off
|
||||
case (false, true):
|
||||
return .nonWiFiInterfaceOnly
|
||||
case (true, false):
|
||||
|
||||
@@ -45,7 +45,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||
self.tunnelsManager = tunnelsManager
|
||||
self.tunnel = tunnel
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
super.init(style: .grouped)
|
||||
loadSections()
|
||||
loadVisibleFields()
|
||||
@@ -60,7 +60,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||
}
|
||||
onDemandObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in
|
||||
// Handle On-Demand getting turned on/off outside of the app
|
||||
self?.onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
self?.onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
self?.updateActivateOnDemandFields()
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
|
||||
func tunnelSaved(tunnel: TunnelContainer) {
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
loadSections()
|
||||
loadVisibleFields()
|
||||
title = tunnel.name
|
||||
|
||||
@@ -60,7 +60,7 @@ class TunnelEditTableViewController: UITableViewController {
|
||||
self.tunnelsManager = tunnelsManager
|
||||
self.tunnel = tunnel
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
super.init(style: .grouped)
|
||||
loadSections()
|
||||
}
|
||||
@@ -113,10 +113,10 @@ class TunnelEditTableViewController: UITableViewController {
|
||||
ErrorPresenter.showErrorAlert(title: alertTitle, message: errorMessage, from: self)
|
||||
tableView.reloadData() // Highlight erroring fields
|
||||
case .saved(let tunnelConfiguration):
|
||||
let activateOnDemandSetting = ActivateOnDemandSetting(with: onDemandViewModel.toOnDemandOption())
|
||||
let onDemandOption = onDemandViewModel.toOnDemandOption()
|
||||
if let tunnel = tunnel {
|
||||
// We're modifying an existing tunnel
|
||||
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: activateOnDemandSetting) { [weak self] error in
|
||||
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] error in
|
||||
if let error = error {
|
||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||
} else {
|
||||
@@ -126,7 +126,7 @@ class TunnelEditTableViewController: UITableViewController {
|
||||
}
|
||||
} else {
|
||||
// We're adding a new tunnel
|
||||
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: activateOnDemandSetting) { [weak self] result in
|
||||
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] result in
|
||||
if let error = result.error {
|
||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||
} else {
|
||||
|
||||
@@ -97,7 +97,7 @@ class TunnelDetailTableViewController: NSViewController {
|
||||
self.tunnelsManager = tunnelsManager
|
||||
self.tunnel = tunnel
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
updateTableViewModelRowsBySection()
|
||||
updateTableViewModelRows()
|
||||
@@ -492,7 +492,7 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
||||
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
|
||||
func tunnelSaved(tunnel: TunnelContainer) {
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(setting: tunnel.activateOnDemandSetting)
|
||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
||||
updateTableViewModelRowsBySection()
|
||||
updateTableViewModelRows()
|
||||
updateStatus()
|
||||
|
||||
@@ -84,13 +84,6 @@ class TunnelEditViewController: NSViewController {
|
||||
return button
|
||||
}()
|
||||
|
||||
let activateOnDemandOptions: [ActivateOnDemandOption] = [
|
||||
.none,
|
||||
.anyInterface(.anySSID),
|
||||
.wiFiInterfaceOnly(.anySSID),
|
||||
.nonWiFiInterfaceOnly
|
||||
]
|
||||
|
||||
let tunnelsManager: TunnelsManager
|
||||
let tunnel: TunnelContainer?
|
||||
var onDemandViewModel: ActivateOnDemandViewModel
|
||||
@@ -106,7 +99,7 @@ class TunnelEditViewController: NSViewController {
|
||||
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) {
|
||||
self.tunnelsManager = tunnelsManager
|
||||
self.tunnel = tunnel
|
||||
self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(setting: tunnel!.activateOnDemandSetting) : ActivateOnDemandViewModel()
|
||||
self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(option: tunnel!.onDemandOption) : ActivateOnDemandViewModel()
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
@@ -223,7 +216,7 @@ class TunnelEditViewController: NSViewController {
|
||||
|
||||
onDemandViewModel.isNonWiFiInterfaceEnabled = onDemandEthernetCheckbox.state == .on
|
||||
onDemandWiFiControls.saveToViewModel()
|
||||
let onDemandSetting = ActivateOnDemandSetting(with: onDemandViewModel.toOnDemandOption())
|
||||
let onDemandOption = onDemandViewModel.toOnDemandOption()
|
||||
|
||||
let isTunnelModifiedWithoutChangingName = (tunnel != nil && tunnel!.name == name)
|
||||
guard isTunnelModifiedWithoutChangingName || tunnelsManager.tunnel(named: name) == nil else {
|
||||
@@ -259,7 +252,7 @@ class TunnelEditViewController: NSViewController {
|
||||
|
||||
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, onDemandOption: onDemandOption) { [weak self] error in
|
||||
self?.setUserInteractionEnabled(true)
|
||||
if let error = error {
|
||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||
@@ -271,7 +264,7 @@ class TunnelEditViewController: NSViewController {
|
||||
} else {
|
||||
// We're creating a new tunnel
|
||||
AppStorePrivacyNotice.show(from: self, into: tunnelsManager) { [weak self] in
|
||||
self?.tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, activateOnDemandSetting: onDemandSetting) { [weak self] result in
|
||||
self?.tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] result in
|
||||
self?.setUserInteractionEnabled(true)
|
||||
if let error = result.error {
|
||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||
|
||||
Reference in New Issue
Block a user