Added extra workarounds for Gnome VFS being used. If it's there, it's

used instead of xdg-open
This commit is contained in:
nathan 2018-01-13 19:22:24 +01:00
parent 24297b117e
commit c3146ea719
2 changed files with 13 additions and 11 deletions

View File

@ -32,8 +32,9 @@ import dorkbox.util.jna.linux.GtkEventDispatch;
@SuppressWarnings({"WeakerAccess", "Convert2Lambda", "Duplicates"}) @SuppressWarnings({"WeakerAccess", "Convert2Lambda", "Duplicates"})
public public
class Desktop { class Desktop {
// used only for ubuntu + unity // used for any linux system that has it...
private static final boolean UBUNTU_GVFS_VALID = OSUtil.Linux.isUbuntu() && OSUtil.DesktopEnv.isUnity() && new File("/usr/bin/gvfs-open").canExecute(); 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. * 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) // 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) // 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) { if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) {
launch(uri.toString()); launchNix(uri.toString());
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.BROWSE)) { .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) // 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) // 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) { if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) {
launch(uri.toString()); launchNix(uri.toString());
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.MAIL)) { .isSupported(java.awt.Desktop.Action.MAIL)) {
@ -200,7 +201,7 @@ class Desktop {
path = "file://" + path; path = "file://" + path;
} }
launch(path); launchNix(path);
} }
else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop()
.isSupported(java.awt.Desktop.Action.OPEN)) { .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 * 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 * 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 * @param path the path to open
*/ */
private static private static
void launch(final String path) { void launchNix(final String path) {
// ubuntu, once again, takes the cake for stupidity. if (GVFS_VALID) {
if (UBUNTU_GVFS_VALID) { // ubuntu, fedora, etc MIGHT have access to gvfs-open. Ubuntu is also VERY buggy with xdg-open!!
// ubuntu has access to gvfs-open. Ubuntu is also VERY buggy with xdg-open!! ShellExecutor.run(GVFS, path);
ShellExecutor.run("gvfs-open", path);
} }
else if (OSUtil.DesktopEnv.isGnome() && GnomeVFS.isInited) { else if (OSUtil.DesktopEnv.isGnome() && GnomeVFS.isInited) {
GtkEventDispatch.dispatch(new Runnable() { GtkEventDispatch.dispatch(new Runnable() {
@Override @Override

View File

@ -48,6 +48,7 @@ class GnomeVFS {
library = JnaHelper.register("libgnomevfs-3", GnomeVFS.class); library = JnaHelper.register("libgnomevfs-3", GnomeVFS.class);
} }
//noinspection StatementWithEmptyBody
if (library == null) { if (library == null) {
// not loading :/ // not loading :/
// fail silently, because we only use this for loading URLs, and have fallbacks in place // fail silently, because we only use this for loading URLs, and have fallbacks in place