Debounce Live Activity ending on BLE disconnect, auto-resume on reconnect
A dropped BLE connection ended the Live Activity immediately, which flickered off and on during the brief, routine disconnects that happen constantly while driving. It now waits 12s before actually ending, and if the sensor reconnects within that window the pending end is simply cancelled. If the disconnect does outlast the grace period and the activity really ends, reconnecting afterwards restarts it automatically with the last known reading, since that wasn't a deliberate user stop. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
004e64e933
commit
7dcb564cbf
@@ -927,7 +927,17 @@ extension BluetoothManager: CBCentralManagerDelegate {
|
||||
queue: queue,
|
||||
onUpdate: { [weak self] snapshot in self?.record(snapshot) },
|
||||
onStateChange: { [weak self] state in
|
||||
self?.publish { self?.linkStates[device.id] = state }
|
||||
self?.publish {
|
||||
self?.linkStates[device.id] = state
|
||||
if state == .live {
|
||||
// Verbindung wieder da: ein anstehendes Ende
|
||||
// verwerfen oder eine zwischenzeitlich doch schon
|
||||
// beendete Live Activity wieder aufnehmen.
|
||||
self?.activityManager?.handleReconnect(
|
||||
deviceID: device.id,
|
||||
state: self?.levelStates[device.id] ?? LevelState())
|
||||
}
|
||||
}
|
||||
},
|
||||
onLevelState: { [weak self] state in
|
||||
self?.publish {
|
||||
@@ -1023,7 +1033,13 @@ extension BluetoothManager: CBCentralManagerDelegate {
|
||||
.map { Date().timeIntervalSince($0) } ?? 0
|
||||
|
||||
if let device = managed[peripheral.identifier] {
|
||||
publish { self.linkStates[device.id] = .searching }
|
||||
let deviceName = store.devices.first { $0.id == device.id }?.name ?? ""
|
||||
publish {
|
||||
self.linkStates[device.id] = .searching
|
||||
// Erst nach einer Gnadenfrist wirklich beenden – sonst
|
||||
// flackerte die Live Activity bei jedem kurzen Funkloch.
|
||||
self.activityManager?.handleDisconnect(deviceID: device.id, deviceName: deviceName)
|
||||
}
|
||||
if lifetime >= stableConnection {
|
||||
// Die Verbindung stand und ist weggefallen - im Fahrzeug der
|
||||
// Normalfall. Kurz durchatmen, dann wieder ran, sonst wäre das
|
||||
|
||||
Reference in New Issue
Block a user