feat: add Flutter USB mirroring and single-instance desktop clients

This commit is contained in:
tongtong committed 2026-11-12 23:16:56 +08:00
1 parent 3a7bb071f0
commit a339465392
30 files changed
+1688 -104

No files matched your search

+28
View File
@@ -6,6 +6,7 @@ Future<void> main(List<String> args) async {
final repo = ManagerRepository(stdout.writeln);
try {
await repo.init();
repo.settings.usbMode = args.contains('--usb');
final devices = await repo.devices();
stdout.writeln(
'API devices: ${devices.map((d) => "${d.id} busy=${d.busy}").join(", ")}',
@@ -40,6 +41,33 @@ Future<void> main(List<String> args) async {
}
stdout.writeln('scrcpy process alive: ${s.screen!.pid}');
}
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
// must either select this virtual serial or report multiple USB devices.
try {
final selected = await repo.run(s.adb, ['-d', 'get-serialno']);
if (selected.trim() != s.endpoint) {
throw StateError('USB-only selection did not include virtual device');
}
} on ProcessException catch (error) {
if (!error.message.contains('more than one')) {
rethrow;
}
}
stdout.writeln('Native USB-only selection verified; get-devpath=$path');
await repo.disconnect(s.id);
await Future<void>.delayed(const Duration(seconds: 2));
final listing = await repo.run(s.adb, ['devices']);
if (listing
.split('\n')
.any((line) => line.startsWith('${s.endpoint}\t'))) {
throw StateError('USB transport was not removed');
}
if (repo.reservedPorts.isNotEmpty) {
throw StateError('Ports leaked after USB disconnect');
}
}
stdout.writeln('LIVE PASS');
} finally {
await repo.shutdown();