Retry 60 times to reconnect (#2846)

* Reconnect 60 times to reconnect, every second
* Fix "in limbo" animation to occur during reconnecting, disconnecting,
and reasserting states (up to 60 seconds)
This commit is contained in:
Jamil
2023-12-09 16:46:44 -05:00
committed by GitHub
parent a8c0c5255f
commit 46a950da84
2 changed files with 11 additions and 12 deletions

View File

@@ -59,7 +59,9 @@ final class AuthStore: ObservableObject {
private var status: NEVPNStatus = .invalid
private static let maxReconnectionAttemptCount = 3
// Try to automatically reconnect on network changes
private static let maxReconnectionAttemptCount = 60
private let reconnectDelaySecs = 1
private var reconnectionAttemptsRemaining = maxReconnectionAttemptCount
private init(tunnelStore: TunnelStore) {
@@ -214,9 +216,9 @@ final class AuthStore: ObservableObject {
self.reconnectionAttemptsRemaining = self.reconnectionAttemptsRemaining - 1
if shouldReconnect {
self.logger.log(
"\(#function): Will try to reconnect after 1 second (\(self.reconnectionAttemptsRemaining) attempts after this)"
"\(#function): Will try every second to reconnect (\(self.reconnectionAttemptsRemaining) attempts after this)"
)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(self.reconnectDelaySecs)) {
self.logger.log("\(#function): Trying to reconnect")
self.startTunnel()
}

View File

@@ -30,7 +30,6 @@
}
private lazy var signedOutIcon = NSImage(named: "MenuBarIconSignedOut")
private lazy var signedInConnectedIcon = NSImage(named: "MenuBarIconSignedInConnected")
private lazy var signedInNotConnectedIcon = NSImage(named: "MenuBarIconSignedInNotConnected")
private lazy var connectingAnimationImages = [
NSImage(named: "MenuBarIconConnecting1"),
@@ -260,22 +259,20 @@
return self.signedOutIcon
case .signedIn:
switch self.tunnelStatus {
case .invalid, .disconnected, .reasserting:
return self.signedInNotConnectedIcon
case .connected:
self.stopConnectingAnimation()
return self.signedInConnectedIcon
case .connecting, .disconnecting:
case .connecting, .disconnecting, .reasserting:
self.startConnectingAnimation()
return self.connectingAnimationImages.last!
case .invalid, .disconnected:
self.stopConnectingAnimation()
return self.signedOutIcon
@unknown default:
return nil
}
}
}()
if self.tunnelStatus == .connecting || self.tunnelStatus == .disconnecting {
self.startConnectingAnimation()
} else {
self.stopConnectingAnimation()
}
}
private func startConnectingAnimation() {