feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

@@ -0,0 +1,37 @@
import 'dart:io';
import 'package:open_dir/open_dir.dart';
import 'package:path/path.dart' as path;
import 'package:url_launcher/url_launcher_string.dart';
class FileExplorer {
static Future<void> openAndSelectFile(String filePath) async {
if (await FileSystemEntity.isFile(filePath)) {
_openFile(filePath);
} else if (await FileSystemEntity.isDirectory(filePath)) {
await _openDirectory(filePath);
} else {
// If file does not exist, open its parent directory
final parentPath = path.dirname(filePath);
if (await FileSystemEntity.isDirectory(parentPath)) {
await _openDirectory(parentPath);
}
}
}
static Future<void> _openDirectory(String directoryPath) async {
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
await OpenDir().openNativeDir(path: directoryPath);
} else {
await launchUrlString("file://$directoryPath");
}
}
static Future<void> _openFile(String filePath) async {
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
final fileName = path.basename(filePath);
final parentPath = path.dirname(filePath);
await OpenDir()
.openNativeDir(path: parentPath, highlightedFileName: fileName);
}
}
}