Repository navigation
refactor: simplify device_provider — remove legacy polling, use reactive native reconnect - #5915
Conversation
When the user disconnects from Device Info page, set _manualDisconnect flag so onDeviceDisconnected skips periodicConnect and cancels the reconnection timer.
Greptile SummaryThis PR removes the Dart-side 15-second polling/reconnection timer ( Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Flutter App
participant DP as DeviceProvider
participant DS as DeviceService
participant NT as NativeBleTransport
participant OS as iOS/Android BLE
Note over App,OS: Cold start / HomePageWrapper init
App->>DP: initiateConnection('HomePageWrapper')
DP->>DS: ensureConnection(pairedId, force: true)
DS->>DS: _connectToDevice(id)<br/>dispose old transport first
DS->>NT: connect(onConnectionStateChanged)
NT->>OS: native connect request
OS-->>NT: connected callback
NT-->>DS: onDeviceConnectionStateChanged(connected)
DS-->>DP: onDeviceConnectionStateChanged(connected)
DP->>DP: _handleDeviceConnected → _onDeviceConnected
Note over App,OS: Device goes out of range
OS-->>NT: disconnected callback
NT-->>DS: onDeviceConnectionStateChanged(disconnected)
DS-->>DP: onDeviceConnectionStateChanged(disconnected)
DP->>DP: onDeviceDisconnected<br/>[_manualDisconnect=false → schedule 30s notification]
OS->>NT: native auto-reconnect (no Dart polling)
NT-->>DS: onDeviceConnectionStateChanged(connected)
DS-->>DP: _handleDeviceConnected
Note over App,OS: User-initiated disconnect / DFU
App->>DP: prepareDFU()
DP->>DP: setFirmwareUpdateInProgress(true)
DP->>DP: _bleDisconnectDevice → _manualDisconnect=true
DP->>DS: ensureConnection + disconnect()
DS-->>DP: onDeviceConnectionStateChanged(disconnected)
DP->>DP: onDeviceDisconnected<br/>[_manualDisconnect=true → return early, no notification]
Note over App,OS: Onboarding (no paired device)
App->>DP: initiateConnection('FoundDevices')
DP->>DP: _startDiscoveryScanning()<br/>Timer.periodic 10s
DP->>DS: discover() every 10s
DS-->>DP: onDevices(foundDevices)
|
…tive reconnect Remove Dart-side 15s polling timer (_reconnectionTimer, _startPollingReconnect, _scanConnectDevice) that raced with NativeBleTransport auto-reconnect. Replace periodicConnect with initiateConnection that calls ensureConnection once. Native iOS CoreBluetooth / Android CompanionDeviceService handles reconnection. Keep a discovery-only timer for onboarding (scanning for new devices). Fix prepareDFU to use setFirmwareUpdateInProgress instead of _reconnectAt DateTime hack.
Always call transport.dispose() in _connectToDevice before nulling _connection. Previously, if a connection was in disconnected state (e.g. after timeout), the old NativeBleTransport stayed registered in BleBridge, leaking callbacks.
OmiGlass OTA page was missing resetFirmwareUpdateState() in dispose(), unlike firmware_update.dart. This left _isFirmwareUpdateInProgress true after leaving the page, permanently suppressing firmware update checks.
|
@greptile-apps re-review |
…ive native reconnect (BasedHardware#5915) ## Summary - Remove Dart-side 15s polling reconnection timer that raced with NativeBleTransport auto-reconnect (iOS CoreBluetooth / Android CompanionDeviceService) - Replace `periodicConnect` with `initiateConnection` — single `ensureConnection` call, native handles retries - Simplify `scanAndConnectToDevice` — direct connection, no fragile 2s delays or redundant queries - Fix `prepareDFU` to use `setFirmwareUpdateInProgress` instead of `_reconnectAt` DateTime hack that only suppressed polling for 30s - Fix transport BleBridge registration leak when replacing stale connections in `DeviceService._connectToDevice` - Fix OmiGlass OTA page not resetting `_isFirmwareUpdateInProgress` in `dispose()` - Keep discovery-only timer for onboarding (scanning for new devices every 10s) <img width="1036" height="477" alt="Screenshot 2026-03-25 at 3 18 32 PM" src="https://github.com/user-attachments/assets/24183518-49e9-4698-92be-dd5ed472d3f1" /> ## Test plan - [x] Cold start with paired device — connects via native auto-reconnect - [x] Device goes out of range — shows disconnected, reconnects when back in range - [x] Manual disconnect from device info — no reconnect attempt - [x] DFU firmware update — disconnect, update, auto-reconnect after reboot - [ ] OmiGlass OTA — firmware flag resets when leaving page - [x] Onboarding — devices discovered even if turned on after page loads - [x] `flutter test` passes (191/197, 6 pre-existing failures in unrelated widget tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
periodicConnectwithinitiateConnection— singleensureConnectioncall, native handles retriesscanAndConnectToDevice— direct connection, no fragile 2s delays or redundant queriesprepareDFUto usesetFirmwareUpdateInProgressinstead of_reconnectAtDateTime hack that only suppressed polling for 30sDeviceService._connectToDevice_isFirmwareUpdateInProgressindispose()Test plan
flutter testpasses (191/197, 6 pre-existing failures in unrelated widget tests)🤖 Generated with Claude Code