-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix connection on new install / devices without permission #4746
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughAdds USB device removal handling across WEBUSB DFU and PortHandler, updates permission-request handling in the port picker, and removes the previous max-supported API-version dialog/abort path in the serial open flow while adding an early guard for missing selected ports. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/js/protocols/webusbdfu.js (1)
94-97: Consider returning the removed port for consistency.The
handleRemovedDevicemethod is well-structured and mirrorshandleNewDevice. For consistency, consider returning theremovedport object (line 95) sincehandleNewDevicereturns theaddedport at line 92, though this is optional if consumers don't need the return value.handleRemovedDevice(device) { const removed = this.createPort(device); this.dispatchEvent(new CustomEvent("removedDevice", { detail: removed })); + return removed; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/js/port_handler.js(2 hunks)src/js/protocols/webusbdfu.js(1 hunks)src/js/serial_backend.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/js/serial_backend.js
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: blckmn
Repo: betaflight/betaflight-configurator PR: 4521
File: src/js/protocols/WebSerial.js:148-151
Timestamp: 2025-06-19T22:13:09.136Z
Learning: In WebSerial.js, there's a timing issue where the cached `this.ports` array doesn't immediately reflect newly permitted devices after `requestPermissionDevice()` completes. The `getDevices()` method needs to refresh the device list from the browser API to return accurate data immediately following a permission request and user acceptance.
📚 Learning: 2025-06-19T22:13:09.136Z
Learnt from: blckmn
Repo: betaflight/betaflight-configurator PR: 4521
File: src/js/protocols/WebSerial.js:148-151
Timestamp: 2025-06-19T22:13:09.136Z
Learning: In WebSerial.js, there's a timing issue where the cached `this.ports` array doesn't immediately reflect newly permitted devices after `requestPermissionDevice()` completes. The `getDevices()` method needs to refresh the device list from the browser API to return accurate data immediately following a permission request and user acceptance.
Applied to files:
src/js/protocols/webusbdfu.jssrc/js/port_handler.js
📚 Learning: 2025-10-25T21:16:32.474Z
Learnt from: haslinghuis
Repo: betaflight/betaflight-configurator PR: 4379
File: src/js/protocols/TauriSerial.js:203-259
Timestamp: 2025-10-25T21:16:32.474Z
Learning: In TauriSerial (src/js/protocols/TauriSerial.js), the requestPermissionDevice() method is not needed and not invoked. Tauri automatically discovers serial devices through the constructor's loadDevices() and startDeviceMonitoring() calls, bypassing the browser permission model that WebSerial requires. Devices are auto-detected via a 1-second polling interval without user permission prompts.
Applied to files:
src/js/protocols/webusbdfu.jssrc/js/port_handler.js
📚 Learning: 2025-11-24T15:07:25.227Z
Learnt from: haslinghuis
Repo: betaflight/betaflight-configurator PR: 4706
File: src/js/protocols/CapacitorSerial.js:47-47
Timestamp: 2025-11-24T15:07:25.227Z
Learning: In betaflight-configurator's CapacitorSerial protocol (src/js/protocols/CapacitorSerial.js), the fire-and-forget this.loadDevices() call in the constructor is intentional background pre-loading. The actual critical device list loading for UI population is orchestrated by port_handler.js via serial.getDevices("serial"), which properly awaits CapacitorSerial.getDevices() → loadDevices() in a complete async chain. The constructor's async call does not cause race conditions.
Applied to files:
src/js/port_handler.js
📚 Learning: 2025-11-22T21:18:08.814Z
Learnt from: haslinghuis
Repo: betaflight/betaflight-configurator PR: 4706
File: src/js/protocols/CapacitorSerial.js:11-46
Timestamp: 2025-11-22T21:18:08.814Z
Learning: In betaflight-configurator, protocol implementations (WebSerial, CapacitorSerial, WebBluetooth, etc.) are instantiated once in the Serial class constructor and stored as singletons in the _protocols array for the entire application lifetime. They are never destroyed or recreated, so cleanup methods to remove event listeners are not needed.
Applied to files:
src/js/port_handler.js
📚 Learning: 2025-11-28T22:41:59.374Z
Learnt from: haslinghuis
Repo: betaflight/betaflight-configurator PR: 4714
File: src/js/protocols/CapacitorBluetooth.js:135-143
Timestamp: 2025-11-28T22:41:59.374Z
Learning: In betaflight-configurator, WebSerial.js uses a constant path "serial" for all devices, and CapacitorBluetooth.js uses constant path "bluetooth", consistent with the single-device-at-a-time workflow. WebBluetooth.js uses counter-based paths (bluetooth_${counter}), but that's specific to its implementation. The path strategy varies by protocol based on their specific requirements.
Applied to files:
src/js/port_handler.js
🧬 Code graph analysis (1)
src/js/port_handler.js (2)
src/js/protocols/webusbdfu.js (1)
WEBUSBDFU(1279-1279)src/components/eventBus.js (2)
EventBus(3-8)EventBus(3-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build / build
🔇 Additional comments (3)
src/js/protocols/webusbdfu.js (1)
86-86: Critical fix: Disconnect now triggers removal handler.The change from
handleNewDevicetohandleRemovedDevicecorrectly addresses a logical bug where USB disconnect events were incorrectly treated as device additions.src/js/port_handler.js (2)
75-75: LGTM!The USB device removal event listener registration is consistent with the addition listener at line 74 and integrates properly with the new removal handling flow.
149-171: Well-structured USB removal handler with good defensive programming.The
removedUsbDevicemethod correctly mirrors the structure ofremovedSerialDevice(lines 107-137), providing consistent device removal handling across protocols. The defensive path validation and conditional event emission are appropriate.
nerdCopter
left a comment
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.
-briefly tested, flashed, pasted diff. did not deep dive connections. did reset permissions.
|
|
🎉 Do you want to test this code? 🎉 |



Reported Issue: for new installs, new devices, there is no permission yet to allow for connection and after flashing the port is empty and still refers to the DFU port. Trying to connect leaves the configuration in unrecoverable state.
Fix:
onOpenwebusbdfu.js) to remove DFU port after flashingno selectionafter requesting permissionsIssue is here:
After the fix:
Summary by CodeRabbit
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.