mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-10 18:02:06 +00:00
on-demand: View model should account for isActivateOnDemandEnabled
This is needed to correctly handle NETunnelProviderManager's isOnDemandEnabled property getting changed outside of the app. Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
e29c6900e5
commit
01be43aa7a
@ -49,9 +49,10 @@ class ActivateOnDemandViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension ActivateOnDemandViewModel {
|
extension ActivateOnDemandViewModel {
|
||||||
convenience init(option: ActivateOnDemandOption) {
|
convenience init(tunnel: TunnelContainer) {
|
||||||
self.init()
|
self.init()
|
||||||
switch option {
|
if tunnel.isActivateOnDemandEnabled {
|
||||||
|
switch tunnel.onDemandOption {
|
||||||
case .off:
|
case .off:
|
||||||
break
|
break
|
||||||
case .wiFiInterfaceOnly(let onDemandSSIDOption):
|
case .wiFiInterfaceOnly(let onDemandSSIDOption):
|
||||||
@ -65,6 +66,7 @@ extension ActivateOnDemandViewModel {
|
|||||||
(ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption)
|
(ssidOption, selectedSSIDs) = ssidViewModel(from: onDemandSSIDOption)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func toOnDemandOption() -> ActivateOnDemandOption {
|
func toOnDemandOption() -> ActivateOnDemandOption {
|
||||||
switch (isWiFiInterfaceEnabled, isNonWiFiInterfaceEnabled) {
|
switch (isWiFiInterfaceEnabled, isNonWiFiInterfaceEnabled) {
|
||||||
|
@ -45,7 +45,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||||||
self.tunnelsManager = tunnelsManager
|
self.tunnelsManager = tunnelsManager
|
||||||
self.tunnel = tunnel
|
self.tunnel = tunnel
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
super.init(style: .grouped)
|
super.init(style: .grouped)
|
||||||
loadSections()
|
loadSections()
|
||||||
loadVisibleFields()
|
loadVisibleFields()
|
||||||
@ -60,7 +60,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||||||
}
|
}
|
||||||
onDemandObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in
|
onDemandObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in
|
||||||
// Handle On-Demand getting turned on/off outside of the app
|
// Handle On-Demand getting turned on/off outside of the app
|
||||||
self?.onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
self?.onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
self?.updateActivateOnDemandFields()
|
self?.updateActivateOnDemandFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,7 +274,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||||||
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
|
extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
|
||||||
func tunnelSaved(tunnel: TunnelContainer) {
|
func tunnelSaved(tunnel: TunnelContainer) {
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
loadSections()
|
loadSections()
|
||||||
loadVisibleFields()
|
loadVisibleFields()
|
||||||
title = tunnel.name
|
title = tunnel.name
|
||||||
|
@ -60,7 +60,7 @@ class TunnelEditTableViewController: UITableViewController {
|
|||||||
self.tunnelsManager = tunnelsManager
|
self.tunnelsManager = tunnelsManager
|
||||||
self.tunnel = tunnel
|
self.tunnel = tunnel
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
super.init(style: .grouped)
|
super.init(style: .grouped)
|
||||||
loadSections()
|
loadSections()
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class TunnelDetailTableViewController: NSViewController {
|
|||||||
self.tunnelsManager = tunnelsManager
|
self.tunnelsManager = tunnelsManager
|
||||||
self.tunnel = tunnel
|
self.tunnel = tunnel
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
updateTableViewModelRowsBySection()
|
updateTableViewModelRowsBySection()
|
||||||
updateTableViewModelRows()
|
updateTableViewModelRows()
|
||||||
@ -500,7 +500,7 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
|||||||
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
|
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
|
||||||
func tunnelSaved(tunnel: TunnelContainer) {
|
func tunnelSaved(tunnel: TunnelContainer) {
|
||||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
|
||||||
onDemandViewModel = ActivateOnDemandViewModel(option: tunnel.onDemandOption)
|
onDemandViewModel = ActivateOnDemandViewModel(tunnel: tunnel)
|
||||||
updateTableViewModelRowsBySection()
|
updateTableViewModelRowsBySection()
|
||||||
updateTableViewModelRows()
|
updateTableViewModelRows()
|
||||||
updateStatus()
|
updateStatus()
|
||||||
|
@ -99,7 +99,7 @@ class TunnelEditViewController: NSViewController {
|
|||||||
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) {
|
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) {
|
||||||
self.tunnelsManager = tunnelsManager
|
self.tunnelsManager = tunnelsManager
|
||||||
self.tunnel = tunnel
|
self.tunnel = tunnel
|
||||||
self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(option: tunnel!.onDemandOption) : ActivateOnDemandViewModel()
|
self.onDemandViewModel = tunnel != nil ? ActivateOnDemandViewModel(tunnel: tunnel!) : ActivateOnDemandViewModel()
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user