48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:ads_manager/data/manager_repository.dart';
|
|
|
|
Future<void> main(List<String> args) async {
|
|
final repo = ManagerRepository(stdout.writeln);
|
|
try {
|
|
await repo.init();
|
|
final devices = await repo.devices();
|
|
stdout.writeln(
|
|
'API devices: ${devices.map((d) => "${d.id} busy=${d.busy}").join(", ")}',
|
|
);
|
|
final nodes = await repo.get('v2/nodes') as Map<String, dynamic>;
|
|
stdout.writeln('Relay nodes: ${(nodes["nodes"] as List<dynamic>).length}');
|
|
stdout.writeln(await repo.run(repo.settings.adb, ['devices', '-l']));
|
|
if (!args.contains('--connect')) {
|
|
return;
|
|
}
|
|
final device = devices.where((d) => !d.busy).firstOrNull;
|
|
if (device == null) {
|
|
stdout.writeln('SKIP: no idle device');
|
|
return;
|
|
}
|
|
final s = await repo.connect(device.id);
|
|
for (var i = 0; i < 20 && !s.ready && !s.exited; i++) {
|
|
await Future<void>.delayed(const Duration(seconds: 3));
|
|
await repo.monitor();
|
|
}
|
|
if (!s.ready) {
|
|
throw StateError('ADB not ready: ${s.state}');
|
|
}
|
|
stdout.writeln(
|
|
'Remote model: ${await repo.run(s.adb, ['-s', s.endpoint, 'shell', 'getprop', 'ro.product.model'])}',
|
|
);
|
|
if (args.contains('--screen')) {
|
|
await repo.screen(s);
|
|
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}');
|
|
}
|
|
stdout.writeln('LIVE PASS');
|
|
} finally {
|
|
await repo.shutdown();
|
|
}
|
|
}
|