listToolingDaemons function
Lists running Dart Tooling Daemons with dart tooling-daemon --list.
Implementation
Future<List<LiveDaemon>> listToolingDaemons() async {
final String executable = _dartExecutable();
final ProcessResult result;
try {
result = await Process.run(executable, [
'tooling-daemon',
'--list',
'--machine',
]).timeout(const Duration(seconds: 15));
} catch (e) {
throw LiveDiscoveryException(
'Couldn\'t list running apps with `dart tooling-daemon --list` ($e). '
'Pass --uri with the "Dart VM Service is available at" address instead.',
);
}
final Object? decoded;
try {
decoded = jsonDecode('${result.stdout}'.trim());
} on FormatException {
throw LiveDiscoveryException(
'Couldn\'t list running apps: `dart tooling-daemon --list` needs '
'Dart 3.12 or newer. Pass --uri with the "Dart VM Service is available '
'at" address instead.',
);
}
if (result.exitCode != 0 || decoded is! List) {
throw LiveDiscoveryException(
'Couldn\'t list running apps (`dart tooling-daemon --list` exited with '
'${result.exitCode}). Pass --uri with the "Dart VM Service is available '
'at" address instead.',
);
}
return decoded.map(LiveDaemon.fromJson).whereType<LiveDaemon>().toList();
}