(ios) Bug fixes for AppStatusButton. Logic was invalid during flaky connections.
@@ -54,27 +54,36 @@ class ObservableConnectionsMonitor: ObservableObject {
private func update(_ newConnections: Connections) {
connections = newConnections
+ // Connection logic:
+ // When the Internet connection is unreliable, we may cycle thru multiple connection attempts:
+ // 1) disconnected
+ // 2) connecting
+ // 3) disconnected
+ // 4) connecting
+ // ...
+ //
+ // So we want to record the date of the first disconnection (1).
+ // And the date of the first reconnection attempt (2).
+ // Only in the event that we connect are the timestamps reset.
+ // This allows our UI logic to properly count forward from these timestamps
+
if newConnections.global is Lightning_kmpConnection.ESTABLISHED {
// All connections are established
if disconnectedAt != nil {
disconnectedAt = nil
}
+ if connectingAt != nil {
+ connectingAt = nil
+ }
} else {
// One or more connections are disconnected
if disconnectedAt == nil {
disconnectedAt = Date()
}
- }
-
if newConnections.oneOrMoreEstablishing() {
- // We're establishing a connection
if connectingAt == nil {
connectingAt = Date()
}
- } else {
- // Not establishing a connection
- if connectingAt != nil {
- connectingAt = nil
}
}
}
