xworkmate-app/lib/runtime/local_file_revealer.dart
Haitao Pan b1ec29fa36 fix: reveal artifact files without blocking (#24)
Co-authored-by: Haitao Pan <haitao.pan@xworkmate.ai>
2026-06-28 15:44:29 +08:00

40 lines
1.0 KiB
Dart

import 'dart:io';
typedef DetachedProcessLauncher =
Future<void> Function(
String executable,
List<String> arguments, {
required ProcessStartMode mode,
});
Future<void> revealLocalFile(
String targetPath, {
String? operatingSystem,
DetachedProcessLauncher? launchDetached,
}) async {
final launcher = launchDetached ?? _launchDetached;
switch (operatingSystem ?? Platform.operatingSystem) {
case 'macos':
await launcher('open', <String>[
'-R',
targetPath,
], mode: ProcessStartMode.detached);
case 'linux':
await launcher('xdg-open', <String>[
File(targetPath).parent.path,
], mode: ProcessStartMode.detached);
case 'windows':
await launcher('explorer.exe', <String>[
'/select,$targetPath',
], mode: ProcessStartMode.detached);
}
}
Future<void> _launchDetached(
String executable,
List<String> arguments, {
required ProcessStartMode mode,
}) async {
await Process.start(executable, arguments, mode: mode);
}