TunnelsManager: Support for on-demand rules
This commit is contained in:
parent
151ad9de84
commit
b09f3e3992
|
@ -72,6 +72,14 @@ class TunnelsManager {
|
||||||
tunnelProviderManager.localizedDescription = tunnelName
|
tunnelProviderManager.localizedDescription = tunnelName
|
||||||
tunnelProviderManager.isEnabled = true
|
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
|
tunnelProviderManager.saveToPreferences { [weak self] (error) in
|
||||||
defer { self?.isAddingTunnel = false }
|
defer { self?.isAddingTunnel = false }
|
||||||
guard (error == nil) else {
|
guard (error == nil) else {
|
||||||
|
@ -130,6 +138,14 @@ class TunnelsManager {
|
||||||
tunnelProviderManager.localizedDescription = tunnelName
|
tunnelProviderManager.localizedDescription = tunnelName
|
||||||
tunnelProviderManager.isEnabled = true
|
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
|
tunnelProviderManager.saveToPreferences { [weak self] (error) in
|
||||||
defer { self?.isModifyingTunnel = false }
|
defer { self?.isModifyingTunnel = false }
|
||||||
guard (error == nil) else {
|
guard (error == nil) else {
|
||||||
|
@ -213,6 +229,26 @@ class TunnelsManager {
|
||||||
t.refreshConnectionStatus()
|
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 {
|
class TunnelContainer: NSObject {
|
||||||
|
|
Loading…
Reference in New Issue