-
Notifications
You must be signed in to change notification settings - Fork 825
fix: initialization of BoardStateProvider #2850
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 guide (collapsed on small PRs)Reviewer's GuideIntroduce a private Sequence diagram for guarded BoardStateProvider initialization and USB event handlingsequenceDiagram
participant BSP as BoardStateProvider
participant SLC as ScienceLabCommon
participant USB as UsbSerial
participant Event as UsbEvent
BSP->>BSP: initialize()
alt _isProcessing is false
BSP->>BSP: set _isProcessing = true
BSP->>SLC: initialize()
BSP->>SLC: openDevice()
BSP->>BSP: setPSLabVersionIDs()
BSP->>BSP: set _isProcessing = false
alt autoStart is true
USB->>BSP: usbEventStream.listen()
Event->>BSP: ACTION_USB_ATTACHED
alt _isProcessing is false
BSP->>BSP: set _isProcessing = true
BSP->>BSP: attemptToConnectPSLab()
BSP->>SLC: openDevice()
BSP->>BSP: setPSLabVersionIDs()
BSP->>BSP: set _isProcessing = false
end
Event->>BSP: ACTION_USB_DETACHED
BSP->>SLC: isWiFiConnected()
alt not WiFi connected
BSP->>BSP: handle detachment
end
end
end
Class diagram for updated BoardStateProvider initialization logicclassDiagram
class BoardStateProvider {
int pslabVersion
String exportFormat
bool autoStart
bool _isProcessing
ScienceLabCommon scienceLabCommon
Future<void> initialize()
void setPSLabVersionIDs()
}
BoardStateProvider --> ScienceLabCommon
File-Level Changes
Assessment against 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 there - I've reviewed your changes - here's some feedback:
- Make sure to reset
_isProcessingin all code paths (including failed attempts and exceptions) or wrap it in a try/finally to avoid locking further initialization calls. - Store and cancel the
UsbSerial.usbEventStreamsubscription in dispose() to prevent potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Make sure to reset `_isProcessing` in all code paths (including failed attempts and exceptions) or wrap it in a try/finally to avoid locking further initialization calls.
- Store and cancel the `UsbSerial.usbEventStream` subscription in dispose() to prevent potential memory leaks.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Build successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/17013273262/artifacts/3780846837 |
Fixes #2849.
Screenshots / Recordings
Screen_recording_20250816_094216.mp4
Summary by Sourcery
Add processing guard to BoardStateProvider to prevent overlapping initialization and USB connection attempts
Bug Fixes: