Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 370ba173 authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor Committed by Jackeagle
Browse files

Defer bootloader connect for steps requiring user gesture

WebUSB requestDevice() can only be called from a user-initiated event.
When a step has needUserGesture set, skip the automatic connect in
next() and let executeStep handle it when the user clicks.

Also add resetDevice() call before bootloader connect retries to clear
stale USB state, consistent with the existing flashBlob retry logic.
parent ef922e60
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -44,8 +44,13 @@ export class Controller {
          //we need reboot
          await this.deviceManager.reboot(next.mode);
        }
        // Skip connect if the step requires a user gesture, since WebUSB
        // requestDevice() can only be called from a user-initiated event.
        // The connect will happen via executeStep when the user clicks.
        if (!next.needUserGesture) {
          await this.deviceManager.connect(next.mode);
        }
      }
      this.currentIndex++;
      current = this.steps[this.currentIndex];
      this.view.onStepStarted(this.currentIndex, current);
+6 −0
Original line number Diff line number Diff line
@@ -73,6 +73,12 @@ export class Bootloader extends Device {
        const delay = CONNECT_RETRY_DELAY * attempt;
        WDebug.log(`Waiting ${delay}ms before retry...`);
        await new Promise((resolve) => setTimeout(resolve, delay));

        // Try to reset USB device to clear stale state
        if (typeof this.device.resetDevice === 'function') {
          WDebug.log("Attempting USB device reset before reconnect...");
          await this.device.resetDevice();
        }
      }
    }
  }