Skip to content

Commit

Permalink
SNOW-1708383: Fix opening external browser on win (#2053)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman authored Jan 29, 2025
1 parent 9e1a5ac commit 4f01bb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: [email protected]:snowflakedb/casec_precommit.git
rev: v1.11
rev: v1.35.5
hooks:
- id: secret-scanner
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -69,24 +70,22 @@ public HttpPost build(URI uri) {

@Override
public void openBrowser(String ssoUrl) throws SFException {
if (!URLUtil.isValidURL(ssoUrl)) {
throw new SFException(ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl);
}
try {
// start web browser
if (!URLUtil.isValidURL(ssoUrl)) {
throw new SFException(
ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl);
}
if (java.awt.Desktop.isDesktopSupported()) {
URI uri = new URI(ssoUrl);
java.awt.Desktop.getDesktop().browse(uri);
Runtime runtime = Runtime.getRuntime();
Constants.OS os = Constants.getOS();
if (Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(ssoUrl));
} else if (os == Constants.OS.MAC) {
runtime.exec("open " + ssoUrl);
} else if (os == Constants.OS.WINDOWS) {
runtime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", ssoUrl});
} 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);
}
runtime.exec("xdg-open " + ssoUrl);
}
} catch (URISyntaxException | IOException ex) {
throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage());
Expand Down

0 comments on commit 4f01bb8

Please sign in to comment.