Skip to content

Commit

Permalink
fix: open files on linux (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyaseFile authored Oct 3, 2024
1 parent 5ad15cc commit 1d86d14
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions ui/flutter/lib/util/file_explorer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> _isUbuntuOrDebian() async {
final result = await Process.run('lsb_release', ['-i']);
if (result.exitCode != 0) {
return false;
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);
}
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;
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');
}
final output = result.stdout.toString().toLowerCase();
return output.contains('centos');
}
}

0 comments on commit 1d86d14

Please sign in to comment.