eclipse-platform / .github

Common contribution content for eclipse-platform repositories
https://www.eclipse.org/eclipse/
5 stars 10 forks source link

Unable to open an URL in external browser on Ubuntu 22.10 with Firefox snap #86

Open henryju opened 1 year ago

henryju commented 1 year ago

Hi,

I have recently switched to Ubuntu, and I discovered that my plugin is not able to open URLs in the external OS browser anymore.

Nothing happen when trying to open a URL, except this log (sorry, my OS is in french):

env: «https://the_url_i_tried_to_open»: Aucun fichier ou dossier de ce type

which can be translated by

env: «https://the_url_i_tried_to_open»: No file or folder of this type

We are using this API in our plugin:

PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url));

Internally, this API is calling:

Program program = Program.findProgram("html");

that doesn't seem to work well in my case, possibly because of the fact Firefox is now installed as a snap package in Ubuntu. FYI, this is the result of the findProgram call:

image

I found a similar issue on Stack Overflow, but on my side Firefox seems to be correctly declared as default browser in the OS:

$ xdg-mime query default text/html
firefox_firefox.desktop

Interesting part of /var/lib/snapd/desktop/applications/firefox_firefox.desktop:

Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/firefox_firefox.desktop /snap/bin/firefox %u
akurtakov commented 1 year ago

Snaps are Ubuntu specific technology so you may have to look into the code yourself to find a fix for it.

henryju commented 1 year ago

I don't think snap is the real problem here. To me, it looks like a problem with the way the default browser command is parsed from the .desktop file.

As you can see, the command in the Exec section starts with env, so I guess some code somewhere assumes the browser command will be the first "word" of this string. Maybe somewhere inside g_app_info_get_default_for_type, but I could not find more.

akurtakov commented 1 year ago

SWT doesn't parse desktop files but rather relies on gio to do so. It's pretty standalone part of SWT so one should be able to experiment with it fairly easy https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/bundles/org.eclipse.swt/Eclipse%20SWT%20Program/gtk/org/eclipse/swt/program/Program.java#L114

akurtakov commented 1 year ago

Note that g_app_info_get_default_for_type is not code maintained by SWT but comes from glib/gio and is invoked via JNI https://docs.gtk.org/gio/type_func.AppInfo.get_default_for_type.html . If you think this is the faulty part you should create snippet showing the issue and reporting it glib maintainers.

henryju commented 1 year ago

I am definitely not a C developer, but I did my best: https://gitlab.gnome.org/GNOME/glib/-/issues/2901

akurtakov commented 1 year ago

Thank you, it looks quite good report to me for Glib devs to act on.

henryju commented 1 year ago

So apparently, GLib developers are considering that SWT should not use g_app_info_get_executable to run a program. They are about to update the API documentation: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3240/diffs