mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 08:30:29 +00:00
fix: macos directory open (#127)
This commit is contained in:
1 parent
c3b28c7034
commit
e2c4567ed0
1 file changed
+29
-19
@@ -2,27 +2,37 @@ import 'dart:io';
|
||||
|
||||
class FileExplorer {
|
||||
static Future<void> openAndSelectFile(String filePath) async {
|
||||
if (!await FileSystemEntity.isDirectory(filePath) &&
|
||||
!await FileSystemEntity.isFile(filePath)) {
|
||||
return;
|
||||
if (await FileSystemEntity.isFile(filePath)) {
|
||||
_openFile(filePath);
|
||||
} else if (await FileSystemEntity.isDirectory(filePath)) {
|
||||
_openDirectory(filePath);
|
||||
}
|
||||
if (await FileSystemEntity.isDirectory(filePath)) {
|
||||
if (Platform.isWindows) {
|
||||
Process.run('explorer.exe', [filePath]);
|
||||
} else if (Platform.isMacOS || Platform.isLinux) {
|
||||
Process.run('xdg-open', [filePath]);
|
||||
}
|
||||
|
||||
static Future<void> _openDirectory(String directoryPath) async {
|
||||
if (Platform.isWindows) {
|
||||
Process.run('explorer.exe', [directoryPath]);
|
||||
} else if (Platform.isMacOS) {
|
||||
Process.run('open', [directoryPath]);
|
||||
} else if (Platform.isLinux) {
|
||||
if (await _isUbuntuOrDebian()) {
|
||||
Process.run('xdg-open', [directoryPath]);
|
||||
} else if (await _isCentOS()) {
|
||||
Process.run('nautilus', [directoryPath]);
|
||||
}
|
||||
} else if (await FileSystemEntity.isFile(filePath)) {
|
||||
if (Platform.isWindows) {
|
||||
Process.run('explorer.exe', ['/select,', filePath]);
|
||||
} else if (Platform.isMacOS) {
|
||||
Process.run('open', ['-R', filePath]);
|
||||
} else if (Platform.isLinux) {
|
||||
if (await _isUbuntuOrDebian()) {
|
||||
Process.run('xdg-open', [filePath]);
|
||||
} else if (await _isCentOS()) {
|
||||
Process.run('nautilus', ['--select', filePath]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (await _isUbuntuOrDebian()) {
|
||||
Process.run('xdg-open', [filePath]);
|
||||
} else if (await _isCentOS()) {
|
||||
Process.run('nautilus', ['--select', filePath]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user