fix: sort discovered beacons by RSSI (closest first)

Sort the beacon list so strongest signal (closest beacon) appears at the
top. Sorting happens both in BLEManager as beacons are discovered and in
the ScanView list rendering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Schwifty 2026-03-22 23:03:18 +00:00
parent df2a03f15a
commit 2306c10d32
2 changed files with 4 additions and 1 deletions

View file

@ -274,6 +274,9 @@ extension BLEManager: CBCentralManagerDelegate {
) )
discoveredBeacons.append(beacon) discoveredBeacons.append(beacon)
} }
// Keep list sorted by RSSI (strongest/closest first)
discoveredBeacons.sort { $0.rssi > $1.rssi }
} }
} }
} }

View file

@ -301,7 +301,7 @@ struct ScanView: View {
.padding() .padding()
} }
} else { } else {
List(bleManager.discoveredBeacons) { beacon in List(bleManager.discoveredBeacons.sorted { $0.rssi > $1.rssi }) { beacon in
Button { Button {
selectedBeacon = beacon selectedBeacon = beacon
Task { await startProvisioning(beacon) } Task { await startProvisioning(beacon) }