From c3146ea719ada23c6b152cb6a317bcbf52cc89f2 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 13 Jan 2018 19:22:24 +0100 Subject: [PATCH] Added extra workarounds for Gnome VFS being used. If it's there, it's used instead of xdg-open --- src/dorkbox/util/Desktop.java | 23 ++++++++++++----------- src/dorkbox/util/jna/linux/GnomeVFS.java | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/dorkbox/util/Desktop.java b/src/dorkbox/util/Desktop.java index af21b90..6f21ecf 100644 --- a/src/dorkbox/util/Desktop.java +++ b/src/dorkbox/util/Desktop.java @@ -32,8 +32,9 @@ import dorkbox.util.jna.linux.GtkEventDispatch; @SuppressWarnings({"WeakerAccess", "Convert2Lambda", "Duplicates"}) public class Desktop { - // used only for ubuntu + unity - private static final boolean UBUNTU_GVFS_VALID = OSUtil.Linux.isUbuntu() && OSUtil.DesktopEnv.isUnity() && new File("/usr/bin/gvfs-open").canExecute(); + // used for any linux system that has it... + private static final String GVFS = "/usr/bin/gvfs-open"; + private static final boolean GVFS_VALID = new File(GVFS).canExecute(); /** * Launches the default browser to display the specified HTTP address. @@ -76,7 +77,7 @@ class Desktop { // Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT) // Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method) if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) { - launch(uri.toString()); + launchNix(uri.toString()); } else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() .isSupported(java.awt.Desktop.Action.BROWSE)) { @@ -141,7 +142,7 @@ class Desktop { // Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT) // Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method) if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) { - launch(uri.toString()); + launchNix(uri.toString()); } else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() .isSupported(java.awt.Desktop.Action.MAIL)) { @@ -200,7 +201,7 @@ class Desktop { path = "file://" + path; } - launch(path); + launchNix(path); } else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() .isSupported(java.awt.Desktop.Action.OPEN)) { @@ -231,16 +232,16 @@ class Desktop { * Of important note, xdg-open can cause problems in Linux with Chrome installed but not the default browser. It will crash Chrome * if Chrome was open before this app opened a URL * + * There are a number of strange bugs with `xdg-open` and `gnome_vfs_url_show_with_env`, ubuntu, once again takes the cake for stupidity. + * * @param path the path to open */ private static - void launch(final String path) { - // ubuntu, once again, takes the cake for stupidity. - if (UBUNTU_GVFS_VALID) { - // ubuntu has access to gvfs-open. Ubuntu is also VERY buggy with xdg-open!! - ShellExecutor.run("gvfs-open", path); + void launchNix(final String path) { + if (GVFS_VALID) { + // ubuntu, fedora, etc MIGHT have access to gvfs-open. Ubuntu is also VERY buggy with xdg-open!! + ShellExecutor.run(GVFS, path); } - else if (OSUtil.DesktopEnv.isGnome() && GnomeVFS.isInited) { GtkEventDispatch.dispatch(new Runnable() { @Override diff --git a/src/dorkbox/util/jna/linux/GnomeVFS.java b/src/dorkbox/util/jna/linux/GnomeVFS.java index 61775a8..38c3f9a 100644 --- a/src/dorkbox/util/jna/linux/GnomeVFS.java +++ b/src/dorkbox/util/jna/linux/GnomeVFS.java @@ -48,6 +48,7 @@ class GnomeVFS { library = JnaHelper.register("libgnomevfs-3", GnomeVFS.class); } + //noinspection StatementWithEmptyBody if (library == null) { // not loading :/ // fail silently, because we only use this for loading URLs, and have fallbacks in place