flathub / org.freedesktop.Sdk.Extension.openjdk11

9 stars 12 forks source link

Java Swing applications (SWT) lack Desktop integration #15

Open nbenitez opened 3 years ago

nbenitez commented 3 years ago

I've been packaging Java GUI applications in flathub recently, they usually are multiplaform apps (Windows, Mac and Linux) which use Java Swing interface. And most of them fail to open url links from their dialogs or menu items (eg. to visit their project page or issue tracker, or to show their online documentation), another one also failed to launch file browser (eg. Nautilus) to show a local directory.

These apps all use a Java api for Desktop integration, which is the following Desktop class: https://docs.oracle.com/javase/9/docs/api/java/awt/Desktop.html

Unfortunately, the linux desktop integration in java is very old and outdated, it uses the gnome_url_show() call which is provided by deprecated library libgnome which is not even present in modern linux distros. See below how gnome_url_show() is used in the Java source code: https://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.desktop/unix/classes/sun/awt/X11/XDesktopPeer.java#l119

So, in order for Java Swing applications to work well in their Desktop integration I propose to add a small patch to openjdk extension to replace the gnome_url_show() call for one of xdg-open so it works perfectly fine under flatpak when the app manifest also includes the flatpak-xdg-utils module.

Related issue: https://github.com/flatpak/xdg-desktop-portal/issues/519

nbenitez commented 3 years ago

Well, diving a bit more in the Java source, gnome_url_show() is called when libgnome is found, but it also checks whether gtk3 and gtk2 is installed, and calls gtk_show_uri() in that case. Links to that java source: https://hg.openjdk.java.net/jdk/jdk15/file/0dabbdfd97e6/src/java.desktop/unix/native/libawt_xawt/xawt/awt_Desktop.c#l78 https://hg.openjdk.java.net/jdk/jdk15/file/0dabbdfd97e6/src/java.desktop/unix/native/libawt_xawt/awt/gtk_interface.c#l46

I just sent PR #16 to replace those with a call to xdg-open which will work in any desktop not just GTK/Gnome and will also work in the minimal Freedesktop runtime which many Java apps are built upon in flathub.

12people commented 3 years ago

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

nbenitez commented 3 years ago

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

That would be cool, but I see that more as an enhancement, first we need to handle the issue here which is more of a bug, where many java apps are currently buggy in that they cannot open links or local files/directories (those which are allowed by --filesystem flag).

But in your line, I think other buggy behaviours of java apps that may be patched further (after this gets accepted):

12people commented 3 years ago

@nbenitez What license is your HiDPI support script? I'd like to use it in my own Flathub project — FOSStriangulator

nbenitez commented 3 years ago

@nbenitez What license is your HiDPI support script? I'd like to use it in my own Flathub project — FOSStriangulator

Public domain, no license.

12people commented 3 years ago

Wonderful, thank you!

mbooth101 commented 2 years ago

Opening URLs is not the only problem here — file chooser dialogs are as well. It'd be great if that was added too. Or, alternatively, if a new Java package was created that developers could use to easily integrate xdg-desktop-portal into Java apps.

FWIW the Java UI framework SWT has full portal integration because it is built on GTK3 and uses all native chooser dialogs. This is how Eclipse (a large Java application) got full desktop portal integration -- it just inherits it from GTK3.