feat: Open in Folder with support for 3rd file manager (#1045)

This commit is contained in:
unifan authored and GitHub committed 2025-06-07 11:14:58 +08:00
1 parent 7c541e4047
commit 5d84445f8f
3 files changed
+53 -34

No files matched your search

+12 -34
View File
@@ -1,5 +1,6 @@
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 {
@@ -12,42 +13,19 @@ class FileExplorer {
}
static Future<void> _openDirectory(String directoryPath) async {
await launchUrlString("file://$directoryPath");
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) {
Process.run('explorer.exe', ['/select,', filePath]);
} else if (Platform.isMacOS) {
Process.run('open', ['-R', filePath]);
} else if (Platform.isLinux) {
_linuxOpen(filePath);
}
}
static Future<void> _linuxOpen(String filePath) async {
if (await Process.run('which', ['xdg-open'])
.then((value) => value.exitCode == 0)) {
final result = await Process.run('xdg-open', [filePath]);
if (result.exitCode != 0) {
_openWithFileManager(filePath);
}
} else {
_openWithFileManager(filePath);
}
}
static Future<void> _openWithFileManager(String filePath) async {
final desktop = Platform.environment['XDG_CURRENT_DESKTOP'];
if (desktop == null) {
throw Exception('XDG_CURRENT_DESKTOP is not set');
}
if (desktop == 'GNOME') {
await Process.run('nautilus', ['--select', filePath]);
} else if (desktop == 'KDE') {
await Process.run('dolphin', ['--select', filePath]);
} else {
throw Exception('Unsupported desktop environment');
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
final fileName = path.basename(filePath);
final parentPath = path.dirname(filePath);
await OpenDir()
.openNativeDir(path: parentPath, highlightedFileName: fileName);
}
}
}
+40
View File
@@ -723,6 +723,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
open_dir:
dependency: "direct main"
description:
name: open_dir
sha256: a4884b00e5e5795a9b4b3d582ac6a66e9196795ed760dbc3c63b4837c70c5901
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_dir_linux:
dependency: transitive
description:
name: open_dir_linux
sha256: "566cd9e02403971be06af35e1abc8057a4f3f98888c1226042e96a2af333b8bc"
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_dir_macos:
dependency: transitive
description:
name: open_dir_macos
sha256: "51fdc8c3a06c9d571b599b5901045ada23d1440b24c3052c0a66cf3ee4ac901b"
url: "https://pub.dev"
source: hosted
version: "0.0.2"
open_dir_platform_interface:
dependency: transitive
description:
name: open_dir_platform_interface
sha256: ca189abb02d8e3320f9b2493b6d58e3a33f393d5eb4ccbbef02e0bc0fd393872
url: "https://pub.dev"
source: hosted
version: "0.0.2"
open_dir_windows:
dependency: transitive
description:
name: open_dir_windows
sha256: ec48df32ce61adb6f6cede0330d13b0d89714d2ee2df198f32ecd520e3a5d250
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_filex:
dependency: "direct main"
description:
+1
View File
@@ -72,6 +72,7 @@ dependencies:
win32_registry: ^1.1.5
share_handler: ^0.0.22
crypto: ^3.0.6
open_dir: ^0.0.2+1
install_plugin:
git:
url: https://github.com/hui-z/flutter_install_plugin.git