Skip to content

Conversation

@ym
Copy link
Contributor

@ym ym commented Nov 5, 2025

Fixes #244

@ym ym marked this pull request as ready for review November 11, 2025 12:13
Copilot finished reviewing on behalf of ym November 11, 2025 12:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a smart USB reset mechanism that attempts to configure USB gadgets without resetting first, and only resets when necessary. The changes add a UsbResetMode enum with three modes: UsbResetNever, UsbResetAlways, and UsbResetOnDemand. The on-demand mode tries configuration without reset, and if it fails, performs a reset and retries.

  • Added UsbResetMode enum to control USB reset behavior
  • Refactored USB gadget configuration to support retry logic with on-demand resets
  • Updated mass storage and device configuration functions to use appropriate reset modes
  • Fixed TypeScript async callback declarations in UI routes

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/usbgadget/config.go Introduced UsbResetMode enum and refactored configureUsbGadget to implement retry logic with on-demand USB reset
usb_mass_storage.go Updated mass storage functions to use UsbResetOnDemand mode and replaced direct file writes with OverrideGadgetConfig
jsonrpc.go Modified updateUsbRelatedConfig to accept UsbResetMode parameter and updated all call sites with appropriate reset modes
ui/src/routes/devices.$id.settings.general.update.tsx Added async modifier to onClose callback to properly handle async operations
ui/src/routes/devices.$id.settings.general.reboot.tsx Added async modifier to onClose callback and imported sleep utility
ui/src/routes/devices.$id.settings.advanced.tsx Added async modifier to reset config button's onClick handler and imported sleep utility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ym and others added 2 commits November 11, 2025 13:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
// if the initial attempt failed, try to configure the gadget again with the resetUsb flag
if resetUsbMode == UsbResetOnDemand {
u.log.Warn().Err(err).Msg("initial attempt to configure the gadget failed, resetting USB gadget then trying again")
// NOTES: do not use the RebindUsb method here because it will block the transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...do not use the public RebindUsb method...

I completely misread this the first time ;)

@adamshiervani
Copy link
Contributor

Unmounting an mounted image breaks the USB gadget, so there is no mouse or keyboard after unmounting.

  1. Mount any HTTP image
  2. Keyboard & Mouse works.
  3. Unmount image
  4. Keyboard & Mouse doesn't work.

Rebooting is the only thing that solves the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unmounting disc from web ui doesnt unmount from mac

4 participants