支持在 Linux/BSD 平台使用 showFileInExplorer (#3233)
* Update ModListPageSkin.java * Update ModListPageSkin.java * Update FXUtils.java * Update ModListPageSkin.java * 使用 dbus-send * Update FXUtils.java * Update FXUtils.java * update * update --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
@@ -408,6 +408,17 @@ public final class FXUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean testLinuxCommand(String command) {
|
||||||
|
try (final InputStream is = Runtime.getRuntime().exec(new String[]{"which", command}).getInputStream()) {
|
||||||
|
if (is.read() != -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void showFileInExplorer(Path file) {
|
public static void showFileInExplorer(Path file) {
|
||||||
String path = file.toAbsolutePath().toString();
|
String path = file.toAbsolutePath().toString();
|
||||||
|
|
||||||
@@ -416,6 +427,16 @@ public final class FXUtils {
|
|||||||
openCommands = new String[]{"explorer.exe", "/select,", path};
|
openCommands = new String[]{"explorer.exe", "/select,", path};
|
||||||
else if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
|
else if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
|
||||||
openCommands = new String[]{"/usr/bin/open", "-R", path};
|
openCommands = new String[]{"/usr/bin/open", "-R", path};
|
||||||
|
else if (OperatingSystem.CURRENT_OS.isLinuxOrBSD() && testLinuxCommand("dbus-send"))
|
||||||
|
openCommands = new String[]{
|
||||||
|
"dbus-send",
|
||||||
|
"--print-reply",
|
||||||
|
"--dest=org.freedesktop.FileManager1",
|
||||||
|
"/org/freedesktop/FileManager1",
|
||||||
|
"org.freedesktop.FileManager1.ShowItems",
|
||||||
|
"array:string:" + file.toAbsolutePath().toUri(),
|
||||||
|
"string:"
|
||||||
|
};
|
||||||
else
|
else
|
||||||
openCommands = null;
|
openCommands = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user