Skip to content

Commit

Permalink
fix: open files on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
AyaseFile committed Sep 28, 2024
1 parent 5ad15cc commit 49c1d8a
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions ui/flutter/lib/util/file_explorer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,26 @@ 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]);
}
}
}

static Future<bool> _isUbuntuOrDebian() async {
final result = await Process.run('lsb_release', ['-i']);
if (result.exitCode != 0) {
return false;
_linuxOpen(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> _linuxOpen(String filePath) async {
if (await Process.run('which', ['xdg-open'])
.then((value) => value.exitCode == 0)) {
Process.run('xdg-open', [filePath]);
} else {
final desktop = Platform.environment['XDG_CURRENT_DESKTOP'];
if (desktop == null) {
throw Exception('XDG_CURRENT_DESKTOP is not set');
}
if (desktop == 'GNOME') {
Process.run('nautilus', ['--select', filePath]);
} else if (desktop == 'KDE') {
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 49c1d8a

Please sign in to comment.