Skip to content

Commit

Permalink
Fallback method for opening external browser
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbertDM authored Sep 6, 2023
1 parent d157bd5 commit a9b90f4
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,32 @@ public void openBrowser(String ssoUrl) throws SFException {
}
if (java.awt.Desktop.isDesktopSupported()) {
URI uri = new URI(ssoUrl);
java.awt.Desktop.getDesktop().browse(uri);
} else {
Runtime runtime = Runtime.getRuntime();
Constants.OS os = Constants.getOS();
if (os == Constants.OS.MAC) {
runtime.exec("open " + ssoUrl);
} else {
// linux?
runtime.exec("xdg-open " + ssoUrl);
try {
java.awt.Desktop.getDesktop().browse(uri);
}
catch (UnsupportedOperationException e) {
openBrowserOSFallback(ssoUrl);
}
} else {
openBrowserOSFallback(ssoUrl);
}
} catch (URISyntaxException | IOException ex) {
throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage());
}
}

private void openBrowserOSFallback(String ssoUrl) throws IOException {
Runtime runtime = Runtime.getRuntime();
Constants.OS os = Constants.getOS();

if (os == Constants.OS.MAC) {
runtime.exec("open " + ssoUrl);
} else {
// linux?
runtime.exec("xdg-open " + ssoUrl);
}
}

@Override
public void output(String msg) {
System.out.println(msg);
Expand Down

0 comments on commit a9b90f4

Please sign in to comment.