Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: open files on linux #765

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
Loading