feat: improve desktop path selection and USB connection recovery

This commit is contained in:
tongtong committed 2026-11-13 03:14:00 +08:00
1 parent 5aa575f182
commit 6490665af8
28 files changed
+846 -51

No files matched your search

+43 -1
View File
@@ -7,6 +7,7 @@ Future<void> main(List<String> args) async {
try {
await repo.init();
repo.settings.usbMode = args.contains('--usb');
repo.settings.relayOnly = args.contains('--relay-only');
final devices = await repo.devices();
stdout.writeln(
'API devices: ${devices.map((d) => "${d.id} busy=${d.busy}").join(", ")}',
@@ -23,6 +24,7 @@ Future<void> main(List<String> args) async {
return;
}
final s = await repo.connect(device.id);
s.screenPageVisible = true;
for (var i = 0; i < 20 && !s.ready && !s.exited; i++) {
await Future<void>.delayed(const Duration(seconds: 3));
await repo.monitor();
@@ -34,13 +36,53 @@ Future<void> main(List<String> args) async {
'Remote model: ${await repo.run(s.adb, ['-s', s.endpoint, 'shell', 'getprop', 'ro.product.model'])}',
);
if (args.contains('--screen')) {
await repo.screen(s);
await repo.screen(s, embedded: args.contains('--embedded'));
await Future<void>.delayed(const Duration(seconds: 8));
if (s.screen == null) {
throw StateError('scrcpy exited early');
}
stdout.writeln('scrcpy process alive: ${s.screen!.pid}');
}
if (args.contains('--recover')) {
final original = s.process.pid;
final oldBridge = s.usb!.bridge!.pid;
final wantedMode = s.screenEmbedded;
await repo.stop(s.process);
var recovered = false;
for (var i = 0; i < 80; i++) {
await Future<void>.delayed(const Duration(seconds: 1));
await repo.monitor();
if (!s.recovering &&
s.ready &&
s.process.pid != original &&
s.usb!.bridge!.pid != oldBridge &&
s.screen != null) {
recovered = true;
break;
}
}
if (!recovered) {
throw StateError(
'USB/client/screen automatic recovery did not complete: ${s.state}',
);
}
if (s.screenEmbedded != wantedMode) {
throw StateError('Screen mode was not preserved');
}
await Future<void>.delayed(const Duration(seconds: 8));
if (s.screen == null || !s.ready) {
throw StateError('Recovered screen did not remain running');
}
stdout.writeln('RECOVERY PASS: client + USB remount + scrcpy restored');
await repo.stopScreen(s);
for (var i = 0; i < 4; i++) {
await Future<void>.delayed(const Duration(seconds: 1));
await repo.monitor();
}
if (s.screen != null || s.screenWanted) {
throw StateError('Manual stop restarted screen');
}
}
if (args.contains('--usb')) {
final path = await repo.run(s.adb, ['-s', s.endpoint, 'get-devpath']);
// Windows ADB may return "unknown" for get-devpath. USB-only selection