Fallback to xdg-open on Linux when opening URLs (#279)

This also prevents MegaBasterd from hanging at startup if it fails
opening the MEGA SDK URL.

Co-authored-by: guihkx <guihkx@users.noreply.github.com>
This commit is contained in:
Guilherme Silva 2020-12-29 21:25:55 -03:00 committed by GitHub
parent 798f6f28e7
commit b446dba7c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1110,8 +1110,20 @@ public class MiscTools {
public static void openBrowserURL(final String url) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.INFO, "Trying to open URL in external browser: {0}", url);
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(url));
return;
}
if (System.getProperty("os.name").toLowerCase().contains("nux")) {
Process p = Runtime.getRuntime().exec(new String[] { "xdg-open", url });
p.waitFor();
p.destroy();
return;
}
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "Unable to open URL: Unsupported platform.", url);
} catch (Exception ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, ex.getMessage());
}
}