From 362600a74b39d7b09618197d8dae250b794cda36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Ben=C3=ADtez=20Le=C3=B3n?= Date: Sat, 16 Jan 2021 22:37:07 -0400 Subject: [PATCH] Allow AWT Desktop class to launch urls and files even when there's no GTK installed, by replacing gnome_url_show() (which also may call gtk_show_uri()) by 'xdg-open' command, which will work in any desktop and not only GTK/Gnome. It also works when using the minimal Freedesktop runtime, which many Java apps are built upon. https://github.com/flathub/org.freedesktop.Sdk.Extension.openjdk11/issues/15 --- java_desktop_xdg_open.patch | 35 ++++++++++++++++++++ org.freedesktop.Sdk.Extension.openjdk11.yaml | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 java_desktop_xdg_open.patch diff --git a/java_desktop_xdg_open.patch b/java_desktop_xdg_open.patch new file mode 100644 index 0000000..fa293d5 --- /dev/null +++ b/java_desktop_xdg_open.patch @@ -0,0 +1,35 @@ +--- a/src/java.desktop/unix/classes/sun/awt/X11/XDesktopPeer.java 2021-01-16 18:10:28.246735459 -0400 ++++ b/src/java.desktop/unix/classes/sun/awt/X11/XDesktopPeer.java 2021-01-16 22:12:54.371818460 -0400 +@@ -75,7 +75,7 @@ + + static boolean isDesktopSupported() { + initWithLock(); +- return nativeLibraryLoaded && !supportedActions.isEmpty(); ++ return /*nativeLibraryLoaded &&*/ !supportedActions.isEmpty(); + } + + public boolean isSupported(Action type) { +@@ -109,19 +109,17 @@ + } + + private void launch(URI uri) throws IOException { +- byte[] uriByteArray = ( uri.toString() + '\0' ).getBytes(); + boolean result = false; ++ int ret; + XToolkit.awtLock(); + try { +- if (!nativeLibraryLoaded) { +- throw new IOException("Failed to load native libraries."); +- } +- result = gnome_url_show(uriByteArray); ++ ret = Runtime.getRuntime().exec(String.format("xdg-open '%s'", uri.toString())).waitFor(); ++ result = ret == 0; + } finally { + XToolkit.awtUnlock(); + } + if (!result) { +- throw new IOException("Failed to show URI:" + uri); ++ throw new IOException("xdg-open failed with error code "+ ret +" for URI: " + uri); + } + } + diff --git a/org.freedesktop.Sdk.Extension.openjdk11.yaml b/org.freedesktop.Sdk.Extension.openjdk11.yaml index 151fd13..d086194 100644 --- a/org.freedesktop.Sdk.Extension.openjdk11.yaml +++ b/org.freedesktop.Sdk.Extension.openjdk11.yaml @@ -96,6 +96,9 @@ modules: path: 39020dd9b75f - type: patch path: 371bbe373ae0 + - type: patch + # https://github.com/flathub/org.freedesktop.Sdk.Extension.openjdk11/issues/15 + path: java_desktop_xdg_open.patch - name: cacerts buildsystem: simple sources: