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 |
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