TunnelsManager: Support for on-demand rules
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
c5e8b05e8b
commit
39a067cb96
|
@ -72,6 +72,14 @@ class TunnelsManager {
|
|||
tunnelProviderManager.localizedDescription = tunnelName
|
||||
tunnelProviderManager.isEnabled = true
|
||||
|
||||
if (tunnelConfiguration.activationType == .activateManually) {
|
||||
tunnelProviderManager.onDemandRules = []
|
||||
tunnelProviderManager.isOnDemandEnabled = false
|
||||
} else {
|
||||
tunnelProviderManager.onDemandRules = onDemandRules(for: tunnelConfiguration.activationType)
|
||||
tunnelProviderManager.isOnDemandEnabled = true
|
||||
}
|
||||
|
||||
tunnelProviderManager.saveToPreferences { [weak self] (error) in
|
||||
defer { self?.isAddingTunnel = false }
|
||||
guard (error == nil) else {
|
||||
|
@ -130,6 +138,14 @@ class TunnelsManager {
|
|||
tunnelProviderManager.localizedDescription = tunnelName
|
||||
tunnelProviderManager.isEnabled = true
|
||||
|
||||
if (tunnelConfiguration.activationType == .activateManually) {
|
||||
tunnelProviderManager.onDemandRules = []
|
||||
tunnelProviderManager.isOnDemandEnabled = false
|
||||
} else {
|
||||
tunnelProviderManager.onDemandRules = onDemandRules(for: tunnelConfiguration.activationType)
|
||||
tunnelProviderManager.isOnDemandEnabled = true
|
||||
}
|
||||
|
||||
tunnelProviderManager.saveToPreferences { [weak self] (error) in
|
||||
defer { self?.isModifyingTunnel = false }
|
||||
guard (error == nil) else {
|
||||
|
@ -213,6 +229,26 @@ class TunnelsManager {
|
|||
t.refreshConnectionStatus()
|
||||
}
|
||||
}
|
||||
|
||||
func onDemandRules(for activationType: ActivationType) -> [NEOnDemandRule] {
|
||||
switch (activationType) {
|
||||
case .activateManually: return []
|
||||
case .useOnDemandOverWifiAndCellular:
|
||||
return [NEOnDemandRuleConnect()]
|
||||
case .useOnDemandOverWifiOnly:
|
||||
let connectOnWifiRule = NEOnDemandRuleConnect()
|
||||
connectOnWifiRule.interfaceTypeMatch = .wiFi
|
||||
let disconnectOnCellularRule = NEOnDemandRuleDisconnect()
|
||||
disconnectOnCellularRule.interfaceTypeMatch = .cellular
|
||||
return [connectOnWifiRule, disconnectOnCellularRule]
|
||||
case .useOnDemandOverCellularOnly:
|
||||
let connectOnCellularRule = NEOnDemandRuleConnect()
|
||||
connectOnCellularRule.interfaceTypeMatch = .cellular
|
||||
let disconnectOnWifiRule = NEOnDemandRuleDisconnect()
|
||||
disconnectOnWifiRule.interfaceTypeMatch = .wiFi
|
||||
return [connectOnCellularRule, disconnectOnWifiRule]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TunnelContainer: NSObject {
|
||||
|
|
Loading…
Reference in New Issue