From 48511eebb332c9d3e7036fd547289a855d4202a8 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 28 Sep 2017 21:07:39 +0200 Subject: [PATCH] xdg-open now runs outside of the GtkEventDispatch thread --- src/dorkbox/util/Desktop.java | 80 ++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/dorkbox/util/Desktop.java b/src/dorkbox/util/Desktop.java index 2db86ae..85bf629 100644 --- a/src/dorkbox/util/Desktop.java +++ b/src/dorkbox/util/Desktop.java @@ -78,26 +78,28 @@ class Desktop { // Additionally, 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 ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) { - GtkEventDispatch.dispatch(new Runnable() { - @Override - public - void run() { - // there are problems with ubuntu and practically everything. Errors galore, and sometimes things don't even work. - // see: https://bugzilla.mozilla.org/show_bug.cgi?id=672671 - if (OSUtil.DesktopEnv.isUnity() && OSUtil.Linux.isUbuntu()) { - // use xdg-open, because it launches in a new shell and suppresses these errors/warnings. - // it can be really buggy though, so we only use it for ubuntu... - ShellExecutor.run("xdg-open", uri.toString()); + // there are problems with ubuntu and practically everything. Errors galore, and sometimes things don't even work. + // see: https://bugzilla.mozilla.org/show_bug.cgi?id=672671 + if (OSUtil.DesktopEnv.isUnity() && OSUtil.Linux.isUbuntu()) { + // use xdg-open, because it launches in a new shell and suppresses these errors/warnings. + // it can be really buggy though, so we only use it for ubuntu... + ShellExecutor.run("xdg-open", uri.toString()); + } + else { + GtkEventDispatch.dispatch(new Runnable() { + @Override + public + void run() { + if (GtkCheck.gtkIsGreaterOrEqual(3, 22, 0)) { + Pointer pointer = Gtk2.Gtk2.gdk_display_get_default(); + Gtk3.Gtk3.gtk_show_uri_on_window(pointer, uri.toString(), 0, null); + } + else { + Gtk2.Gtk2.gtk_show_uri(Gtk2.Gtk2.gdk_screen_get_default(), uri.toString(), 0, null); + } } - else if (GtkCheck.gtkIsGreaterOrEqual(3, 22, 0)) { - Pointer pointer = Gtk2.Gtk2.gdk_display_get_default(); - Gtk3.Gtk3.gtk_show_uri_on_window(pointer, uri.toString(), 0, null); - } - else { - Gtk2.Gtk2.gtk_show_uri(Gtk2.Gtk2.gdk_screen_get_default(), uri.toString(), 0, null); - } - } - }); + }); + } } else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() .isSupported(java.awt.Desktop.Action.BROWSE)) { @@ -211,26 +213,28 @@ class Desktop { } final String finalPath = path; - GtkEventDispatch.dispatch(new Runnable() { - @Override - public - void run() { - // there are problems with ubuntu and practically everything. Errors galore, and sometimes things don't even work. - // see: https://askubuntu.com/questions/788182/nautilus-not-opening-up-showing-glib-error - if (OSUtil.DesktopEnv.isUnity() && OSUtil.Linux.isUbuntu()) { - // use xdg-open, because it launches in a new shell and suppresses these errors/warnings. - // it can be really buggy though, so we only use it for ubuntu... - ShellExecutor.runShell("xdg-open", finalPath); + // there are problems with ubuntu and practically everything. Errors galore, and sometimes things don't even work. + // see: https://askubuntu.com/questions/788182/nautilus-not-opening-up-showing-glib-error + if (OSUtil.DesktopEnv.isUnity() && OSUtil.Linux.isUbuntu()) { + // use xdg-open, because it launches in a new shell and suppresses these errors/warnings. + // it can be really buggy though, so we only use it for ubuntu... + ShellExecutor.runShell("xdg-open", finalPath); + } + else { + GtkEventDispatch.dispatch(new Runnable() { + @Override + public + void run() { + if (GtkCheck.gtkIsGreaterOrEqual(3, 22, 0)) { + Pointer pointer = Gtk2.Gtk2.gdk_display_get_default(); + Gtk3.Gtk3.gtk_show_uri_on_window(pointer, finalPath, 0, null); + } + else { + Gtk2.Gtk2.gtk_show_uri(Gtk2.Gtk2.gdk_screen_get_default(), finalPath, 0, null); + } } - else if (GtkCheck.gtkIsGreaterOrEqual(3, 22, 0)) { - Pointer pointer = Gtk2.Gtk2.gdk_display_get_default(); - Gtk3.Gtk3.gtk_show_uri_on_window(pointer, finalPath, 0, null); - } - else { - Gtk2.Gtk2.gtk_show_uri(Gtk2.Gtk2.gdk_screen_get_default(), finalPath, 0, null); - } - } - }); + }); + } } else if (java.awt.Desktop.isDesktopSupported() && java.awt.Desktop.getDesktop() .isSupported(java.awt.Desktop.Action.OPEN)) {