Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Use freedesktop's xdg-open to get default web browser on Linux systems #260

Closed
Tristan971 opened this issue Oct 30, 2018 · 7 comments
Closed
Labels
enhancement New feature or request

Comments

@Tristan971
Copy link
Contributor

Tristan971 commented Oct 30, 2018

Hello, I am pretty sure this has been reported already (at the very least, probably even discussed) but I just cannot find it, please do not hesitate to let me know if you have the original handy.

On Linux systems, right now (i.e. in OpenJFX 11) getting a handle on the default browser is done through a static array in HostServicesDelegate as so :

 static final String[] browsers = {"google-chrome", "firefox", "opera", 
"konqueror", "mozilla"};

which is then iterated over to find the installed one and run a process to open it :

} else { //assume Unix or Linux
    String browser = null;
    for (String b : browsers) {
        if (browser == null && Runtime.getRuntime().exec(
                new String[]{"which", b}).getInputStream().read() != -1) {
            Runtime.getRuntime().exec(new String[]{browser = b, uri});
        }
    }
    if (browser == null) {
        throw new Exception("No web browser found");
    }
}

This :

  • Doesn't support third-party browsers (i.e. Brave, Vivaldi, Pale Moon and others)
  • Doesn't support beta versions of some major ones (e.g. Firefox whose beta version binary name is firefox-beta at least on Archlinux derivates)

In regard to these issues, a simple fix would be to rely on the widely accepted default of relying on freedesktop's xdg-open command which will automatically select any OS-registered browser in most GUI-enabled Linux environments (while JavaFX has some headless support I find it more reasonable to assume users generally have a GUI given the very nature of JavaFX).

I propose a fix that would remove the array and its subsequent usage to be replaced by xdg-open.

In the very same vein, I would assume that this issue (or another one at least) should use Apple's open command for macOS rather than relying on AWT's Desktop class.

Thank you for your consideration and sorry if this has been debated but again I could not easily find a place where such a debate would have been had (at least not in a reasonable search time).

--- (If not clear I would of course volunteer for implementing that/these fixes)

@Tristan971 Tristan971 changed the title Use freedesktop's xdg-open to get default web browser on Linux systems Use freedesktop's xdg-open to get default web browser on Linux systems Oct 30, 2018
@kevinrushforth
Copy link
Collaborator

This seems like a reasonable idea. If you are interested in contributing a fix for this change, please read CONTRIBUTING.md.

Two recommendations:

  1. Address the Linux version first (using the bug ID you will file for this issue) and then file a separate issue for macOS
  2. Leave the existing mechanism in place for Linux as a fallback in case xdg-open is not present.

@Tristan971
Copy link
Contributor Author

Alright, will go through with the oracle agreement then the linux version 👍 Thanks for the reply!

@Tristan971
Copy link
Contributor Author

(by the way this is not abandoned, it's just the OCA being quite the hurdle to get done)

@kevinrushforth
Copy link
Collaborator

OK

@kevinrushforth
Copy link
Collaborator

kevinrushforth commented Nov 16, 2018

In the mean time, can you file an enhancement request at https://bugreport.java.com/ ?

@kevinrushforth kevinrushforth added the enhancement New feature or request label Nov 16, 2018
@kevinrushforth
Copy link
Collaborator

Tracked in JBS as: JDK-8214069.

@kevinrushforth
Copy link
Collaborator

I see that your OCA has been processed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants