Tunnels manager: After saving after activating on-demand, reload tunnel

This commit is contained in:
Roopesh Chander 2018-11-14 13:00:52 +05:30
parent 6da2b4d0be
commit ed1bae8ad0
1 changed files with 16 additions and 3 deletions

View File

@ -135,6 +135,7 @@ class TunnelsManager {
tunnelProviderManager.localizedDescription = tunnelName
tunnelProviderManager.isEnabled = true
let isActivatingOnDemand = (!tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled)
activateOnDemandSetting.apply(on: tunnelProviderManager)
tunnelProviderManager.saveToPreferences { [weak self] (error) in
@ -158,9 +159,21 @@ class TunnelsManager {
tunnel.beginRestart()
}
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
completionHandler(nil)
if (isActivatingOnDemand) {
// Reload tunnel after saving.
// Without this, the tunnel stopes getting updates on the tunnel status from iOS.
tunnelProviderManager.loadFromPreferences { (error) in
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
guard (error == nil) else {
os_log("Modify: Re-loading after saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
completionHandler(TunnelManagementError.vpnSystemErrorOnModifyTunnel)
return
}
completionHandler(nil)
}
} else {
completionHandler(nil)
}
}
}
}