Skip to content

Commit f06c98c

Browse files
author
刘威
committed
fix: refresh device list after adb startup
- retry initial adb device enumeration during startup - push devices:updated events from the main process to the renderer - bump version to 0.7.48
1 parent 68c3147 commit f06c98c

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adb-proxy-browser",
3-
"version": "0.7.47",
3+
"version": "0.7.48",
44
"description": "A customized browser that routes traffic through ADB tunnel to phone proxy (Clash)",
55
"main": "src/main/index.js",
66
"scripts": {

src/main/adb/device.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { getBundledAdbPath } = require('./download');
88

99
const ADB_SERVER_PORT = 5037;
1010
const 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
1315
const 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
*/

src/main/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,13 @@ app.whenReady().then(async () => {
10121012
connectionManager = new ConnectionManager();
10131013
perf.mark('ConnectionManager created');
10141014

1015+
connectionManager.adbManager.onDevicesUpdated((devices) => {
1016+
log.info('IPC', 'devices:updated push: devices=', devices.length);
1017+
if (mainWindow && !mainWindow.isDestroyed()) {
1018+
mainWindow.webContents.send('device:changed', devices);
1019+
}
1020+
});
1021+
10151022
terminalManager = new TerminalManager(connectionManager.adbManager);
10161023
perf.mark('TerminalManager created');
10171024

0 commit comments

Comments
 (0)