Skip to content

fix(connections): improve BLE scan reliability and UI lifecycle#5329

Merged
jamesarich merged 2 commits intomainfrom
fix/desktop-ble
May 2, 2026
Merged

fix(connections): improve BLE scan reliability and UI lifecycle#5329
jamesarich merged 2 commits intomainfrom
fix/desktop-ble

Conversation

@jamesarich
Copy link
Copy Markdown
Collaborator

On macOS, CoreBluetooth caches peripheral identifiers, which can cause scans filtered by address to time out. This change switches to scanning by service UUID and filtering the results manually to ensure reliable discovery on Desktop. It also refines the UI scan logic to prevent state changes from interrupting active scans.

  • Scan by service UUID and filter results by address in BleRadioTransport to fix Desktop timeouts
  • Decouple scan auto-start from cleanup in ConnectionsScreen using LaunchedEffect and DisposableEffect(Unit)
  • Prevent scan restarts when bleAutoScan state is updated from disk or DataStore
  • Ensure stopBleScan() is called only when the screen is actually disposed

On macOS, CoreBluetooth caches peripheral identifiers, which can cause scans filtered by address to time out. This change switches to scanning by service UUID and filtering the results manually to ensure reliable discovery on Desktop. It also refines the UI scan logic to prevent state changes from interrupting active scans.

- Scan by service UUID and filter results by address in `BleRadioTransport` to fix Desktop timeouts
- Decouple scan auto-start from cleanup in `ConnectionsScreen` using `LaunchedEffect` and `DisposableEffect(Unit)`
- Prevent scan restarts when `bleAutoScan` state is updated from disk or DataStore
- Ensure `stopBleScan()` is called only when the screen is actually disposed
@github-actions github-actions Bot added the bugfix PR tag label May 2, 2026
@jamesarich jamesarich requested a review from Copilot May 2, 2026 11:33
@github-actions github-actions Bot added the enhancement New feature or request label May 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make BLE discovery more reliable across platforms—especially Desktop/CoreBluetooth—while refining the Connections screen’s scan lifecycle so persisted auto-scan state does not unnecessarily interrupt active scans.

Changes:

  • Updated BLE transport discovery to scan by Meshtastic service UUID and then match the selected device in-app.
  • Split BLE scan auto-start from cleanup in ConnectionsScreen using LaunchedEffect plus a disposal-only cleanup effect.
  • Kept scan shutdown tied to screen disposal instead of preference-state recomposition.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/ConnectionsScreen.kt Refactors BLE auto-scan lifecycle handling in the shared Connections UI.
core/network/src/commonMain/kotlin/org/meshtastic/core/network/radio/BleRadioTransport.kt Changes BLE device discovery to service-UUID scanning with manual address matching.

…ion test

Pass both serviceUuid and address to BleScanner.scan() so Android uses
efficient OS-level address filtering while CoreBluetooth (macOS) can
fall back to service UUID discovery when cached identifiers prevent
address-only rescans. Add regression test to lock in this behavior.
@jamesarich jamesarich added this pull request to the merge queue May 2, 2026
Merged via the queue into main with commit 5a95201 May 2, 2026
12 checks passed
@jamesarich jamesarich deleted the fix/desktop-ble branch May 2, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants