mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-07 00:50:27 +00:00
fix: open files on linux (#765)
This commit is contained in:
1 parent
5ad15cc4ac
commit
1d86d14a20
1 file changed
+22
-18
@@ -21,29 +21,33 @@ class FileExplorer {
|
||||
} 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]);
|
||||
_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<bool> _isUbuntuOrDebian() async {
|
||||
final result = await Process.run('lsb_release', ['-i']);
|
||||
if (result.exitCode != 0) {
|
||||
return false;
|
||||
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');
|
||||
}
|
||||
final output = result.stdout.toString().toLowerCase();
|
||||
return output.contains('ubuntu') || output.contains('debian');
|
||||
}
|
||||
|
||||
static Future<bool> _isCentOS() async {
|
||||
final result = await Process.run('cat', ['/etc/os-release']);
|
||||
if (result.exitCode != 0) {
|
||||
return false;
|
||||
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');
|
||||
}
|
||||
final output = result.stdout.toString().toLowerCase();
|
||||
return output.contains('centos');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user