-
Notifications
You must be signed in to change notification settings - Fork 239
fix: BLE connection only allowed one update without app restart #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR overhauls the BLE reconnection flow by ensuring preemptive cleanup in scan and connect states (calling stopScan and disconnect appropriately), refines write operations with added logging and chunk delays for stability, and updates the delete dialog to use responsive padding and adjusted spacings. Sequence diagram for improved BLE reconnection flowsequenceDiagram
actor User
participant App
participant FlutterBluePlus
participant BLEDevice
User->>App: Initiate BLE update
App->>FlutterBluePlus: stopScan() (preemptive)
App->>BLEDevice: disconnect() (preemptive)
App->>FlutterBluePlus: startScan()
FlutterBluePlus-->>App: scanResults
App->>FlutterBluePlus: stopScan() (on device found or error)
App->>BLEDevice: connect()
BLEDevice-->>App: connectionState
App->>BLEDevice: write data in chunks (with delay)
BLEDevice-->>App: write response
App-->>User: Show success or error message
Class diagram for updated BLE state classesclassDiagram
class NormalBleState
class ScanState {
+DataTransferManager manager
+Future<BleState?> processState()
}
class ConnectState {
+ScanResult scanResult
+DataTransferManager manager
+Future<BleState?> processState()
}
class WriteState {
+BluetoothCharacteristic characteristic
+List<List<int>> chunks
+Future<BleState?> processState()
}
NormalBleState <|-- ScanState
NormalBleState <|-- WriteState
RetryBleState <|-- ConnectState
class RetryBleState
class BleState
ScanState ..> DataTransferManager
ConnectState ..> ScanResult
ConnectState ..> DataTransferManager
WriteState ..> BluetoothCharacteristic
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @samruddhi-Rahegaonkar - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `lib/bademagic_module/bluetooth/scan_state.dart:32` </location>
<code_context>
+ orElse: () => throw Exception("Matching device not found."),
);
- if (foundDevice != null) {
- toast.showToast('Device found. Connecting...');
- isCompleted = true;
- nextStateCompleter.complete(ConnectState(
- scanResult: foundDevice!,
- manager: manager,
</code_context>
<issue_to_address>
Duplicate code for handling found device should be removed.
Executing this logic twice may cause issues like repeated toasts or state changes. Please remove the duplicate block to prevent this.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
await FlutterBluePlus.stopScan(); | ||
nextStateCompleter.complete(ConnectState( | ||
scanResult: foundDevice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Duplicate code for handling found device should be removed.
Executing this logic twice may cause issues like repeated toasts or state changes. Please remove the duplicate block to prevent this.
e22fbb7
to
d7b309f
Compare
Build StatusBuild successful. APKs to test: https://github.com/fossasia/badgemagic-app/actions/runs/16806247721/artifacts/3710904334. Screenshots (Android)
Screenshots (iPhone)
Screenshots (iPad)
|
@@ -12,7 +12,13 @@ class ConnectState extends RetryBleState { | |||
@override | |||
Future<BleState?> processState() async { | |||
bool connected = false; | |||
|
|||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you verify this change because I dont think so that it will work by just disconnecting before. We already have this removeIfGone property ro handle this case.
cd6d166
to
6ff02b4
Compare
4e0ed3a
to
96960e5
Compare
fix: duplicate logic removed fix: Squashed all commits into one fix: removed comments
503e457
to
a5c57b4
Compare
@Jhalakupadhyay I have tested it on badge its working fine! |
@samruddhi-Rahegaonkar update the branch and I will merge it |
@samruddhi-Rahegaonkar please update the branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good just add
-Error Handling for Disconnects
-Ensure Disconnect After Write
@nope3472 Everywhere There is a Error Handling in the code and it disconnects after write. |
@hpdang This one is also good to merge. |
Fixes #1329
Changes
Screenshots / Recordings
Checklist:
constants.dart
without hard coding any value.Summary by Sourcery
Fix BLE reconnection flow to allow repeated updates without restarting the app and refine dialog layout adjustments.
Bug Fixes:
Enhancements:
Summary by Sourcery
Improve BLE reconnection flow to allow repeated firmware updates without restarting the app and refine the badge deletion dialog layout
Bug Fixes:
Enhancements: