mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 14:53:44 +00:00
feat: new ui (#1455)
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user