UI: iOS: Tunnels list: Incorporate on-demand-ness in the switch

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander
2021-07-25 01:34:03 +05:30
parent df9934a4b8
commit a115dd3bd9
3 changed files with 44 additions and 10 deletions
@@ -317,10 +317,18 @@ extension TunnelsListTableViewController: UITableViewDataSource {
cell.tunnel = tunnel
cell.onSwitchToggled = { [weak self] isOn in
guard let self = self, let tunnelsManager = self.tunnelsManager else { return }
if isOn {
tunnelsManager.startActivation(of: tunnel)
if tunnel.hasOnDemandRules {
tunnelsManager.setOnDemandEnabled(isOn, on: tunnel) { error in
if error == nil && !isOn {
tunnelsManager.startDeactivation(of: tunnel)
}
}
} else {
tunnelsManager.startDeactivation(of: tunnel)
if isOn {
tunnelsManager.startActivation(of: tunnel)
} else {
tunnelsManager.startDeactivation(of: tunnel)
}
}
}
}