@@ -8,6 +8,8 @@ const { getBundledAdbPath } = require('./download');
88
99const ADB_SERVER_PORT = 5037 ;
1010const HEALTH_CHECK_INTERVAL = 5000 ;
11+ const INITIAL_DEVICE_RETRY_COUNT = 6 ;
12+ const INITIAL_DEVICE_RETRY_DELAY_MS = 500 ;
1113
1214// Platform-specific adb binary paths
1315const ADB_PATHS = {
@@ -337,15 +339,32 @@ class DeviceManager extends EventEmitter {
337339 console . error ( '[ADB] Tracker error:' , err . message ) ;
338340 } ) ;
339341
340- // Initial device list
341- await this . _updateDevices ( ) ;
342+ // When adb has just started, listDevices() may briefly return empty even
343+ // though a USB device is already authorized. Retry a few times so the UI
344+ // does not get stuck on "No Devices" after startup.
345+ await this . _updateDevicesWithRetry ( INITIAL_DEVICE_RETRY_COUNT , INITIAL_DEVICE_RETRY_DELAY_MS ) ;
342346
343347 console . log ( '[ADB] Device tracking started' ) ;
344348 } catch ( err ) {
345349 console . error ( '[ADB] Failed to start device tracking:' , err . message ) ;
346350 }
347351 }
348352
353+ async _updateDevicesWithRetry ( maxAttempts , delayMs ) {
354+ for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
355+ await this . _updateDevices ( ) ;
356+
357+ if ( this . devices . length > 0 || attempt === maxAttempts ) {
358+ return this . devices ;
359+ }
360+
361+ console . log ( `[ADB] No devices yet, retrying device list (${ attempt } /${ maxAttempts } )...` ) ;
362+ await new Promise ( ( resolve ) => setTimeout ( resolve , delayMs ) ) ;
363+ }
364+
365+ return this . devices ;
366+ }
367+
349368 /**
350369 * Update device list
351370 */
0 commit comments