Fix tunnel remaining in 'Activating' state

It uses to remain in 'Activating' state when we don't get a status
update notification, for example, when turning on the tunnel repeatedly
without Internet connectivity.
This commit is contained in:
Roopesh Chander 2018-12-14 17:33:52 +05:30
parent ce112a3f44
commit 34a7e5b558
1 changed files with 19 additions and 1 deletions

View File

@ -358,8 +358,26 @@ class TunnelContainer: NSObject {
@objc dynamic var isActivateOnDemandEnabled: Bool @objc dynamic var isActivateOnDemandEnabled: Bool
var isAttemptingActivation = false var isAttemptingActivation = false {
didSet {
if isAttemptingActivation {
let activationTimer = Timer(timeInterval: 5 /* seconds */, repeats: true) { [weak self] _ in
guard let self = self else { return }
self.refreshStatus()
if self.status == .inactive || self.status == .active {
self.isAttemptingActivation = false // This also invalidates the timer
}
}
self.activationTimer = activationTimer
RunLoop.main.add(activationTimer, forMode: .default)
} else {
self.activationTimer?.invalidate()
self.activationTimer = nil
}
}
}
var activationAttemptId: String? var activationAttemptId: String?
var activationTimer: Timer?
fileprivate let tunnelProvider: NETunnelProviderManager fileprivate let tunnelProvider: NETunnelProviderManager
private var lastTunnelConnectionStatus: NEVPNStatus? private var lastTunnelConnectionStatus: NEVPNStatus?