Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java application fails to launch browser ("The BROWSE action is not supported on the current platform!") #1

Open
mwilck opened this issue Apr 5, 2022 · 5 comments

Comments

@mwilck
Copy link

mwilck commented Apr 5, 2022

I am trying to build a flatpak package for Audiveris. The application fails to open a web browser to show the documentation:

INFO  []                WebBrowser 93   | Desktop.browse http://www.audiveris.org with WebBrowser(java.awt.Desktop) on Linux
Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
	at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:846)
	at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:649)
	at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:687)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:374)
...
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:647)
	... 39 more
Caused by: java.lang.UnsupportedOperationException: The BROWSE action is not supported on the current platform!
	at java.desktop/java.awt.Desktop.checkActionSupport(Desktop.java:381)
	at java.desktop/java.awt.Desktop.browse(Desktop.java:531)
	at org.audiveris.omr.ui.util.WebBrowser.launch(WebBrowser.java:97)
	at org.audiveris.omr.ui.GuiActions.visitWebSite(GuiActions.java:348)
	... 44 more

When this happens, no activity is seen on the DBus session bus, so the Java app doesn't seem to try to address the XDG portal via DBus. This seems to be a known problem (1, 2). I've verified that it doesn't occur if I run the application natively. However there are also some Java applications that seem to be able to open a browser in flatpak. I lack both Java and flatpak experience to judge what exactly is going wrong. Anyway, there seems to be a solution for openJDK11 in 2 that hasn't been merged for more than a year.

The latest version of Audiveris (5.2.5) utilizes openJDK 17, whereas 5.2.4 uses openJDK11. I'm observing the issue in both environments, using org.freedesktop.Sdk.Extension.openjdk11/21.08 and org.freedesktop.Sdk.Extension.openjdk17/21.08, respectively.

What should I do to make this work?

Footnotes

  1. https://github.com/flathub/org.freedesktop.Sdk.Extension.openjdk11/issues/15

  2. https://github.com/flathub/org.freedesktop.Sdk.Extension.openjdk11/pull/16 2

@guihkx
Copy link
Collaborator

guihkx commented Apr 5, 2022

I'm the maintainer of a proprietary Java program on Flathub that tries to do the same thing. Unfortunately, because I'm unable to patch that program, the next best solution I found is to use the GNOME runtime instead of the Freedesktop one, plus a new set of dbus permissions. Something like this:

runtime: org.gnome.Platform
runtime-version: '42'
sdk: org.gnome.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.openjdk17

And add these permissions:

finish-args:
  - --share=ipc
  - --talk-name=org.gtk.vfs.*
  - --filesystem=xdg-run/gvfsd

You can take a look here for the complete manifest file.

Alternatively, you can try to patch Audiveris like this, which will then work on Flatpak without having to switch runtimes.

@mwilck
Copy link
Author

mwilck commented Apr 6, 2022

Thanks! Being a Java noob - if you could patch the program, what would you do?

@guihkx
Copy link
Collaborator

guihkx commented Apr 6, 2022

I'd maybe add some check after line 96:

https://github.com/Audiveris/audiveris/blob/c09447621a7dbe71b218194d2decf9472106746d/src/main/org/audiveris/omr/ui/util/WebBrowser.java#L88-L106

if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
    // Default behavior
    desktop.browse(uri);
} else {
    // Detect Linux and fallback to xdg-open
    if (System.getProperty("os.name").toLowerCase().contains("nux")) {
        Process p = Runtime.getRuntime().exec(new String[] { "xdg-open", uri });
        p.waitFor();
        p.destroy();
    }
}

Very rough implementation and I haven't really tested it though

@mwilck
Copy link
Author

mwilck commented Apr 9, 2022

Thanks a lot!! And apologies, I'd overlooked that you'd actually answered my last question in your first reply already.
Thanks for making it even more explicit for me, really much appreciated. I'll try it and see how it goes.

Anyway, I believe that this should eventually be fixed either in openJDK itself or in flatpak's openJDK package.

@mwilck
Copy link
Author

mwilck commented Apr 9, 2022

I've come up with a slightly different approach now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants