Skip to content

Commit bb41ad7

Browse files
committed
Use win32 ShellExecute API to open URL with default browser
1 parent 229c32c commit bb41ad7

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

arduino-core/src/processing/app/windows/Platform.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import com.sun.jna.Native;
3939
import com.sun.jna.Pointer;
40+
import com.sun.jna.platform.win32.Shell32;
4041
import com.sun.jna.win32.StdCallLibrary;
4142
import com.sun.jna.win32.W32APIOptions;
4243

@@ -129,11 +130,15 @@ public void openURL(String url) throws Exception {
129130
if (file.exists()) {
130131
// in this case convert the path to a "file:" url
131132
url = file.toURI().toString();
132-
133-
// this allows to open the file on Windows 10 that
134-
// has a more strict permission policy for cmd.exe
135133
}
136134
}
135+
if (url.startsWith("http") || url.startsWith("file:")) {
136+
// this allows to open the file on Windows 10 that
137+
// has a more strict permission policy for cmd.exe
138+
final int SW_SHOW = 5;
139+
Shell32.INSTANCE.ShellExecute(null, null, url, null, null, SW_SHOW);
140+
return;
141+
}
137142

138143
// this is not guaranteed to work, because who knows if the
139144
// path will always be c:\progra~1 et al. also if the user has
@@ -150,18 +155,12 @@ public void openURL(String url) throws Exception {
150155
// "Access is denied" in both cygwin and the "dos" prompt.
151156
//Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" +
152157
// referenceFile + ".html");
153-
if (url.startsWith("http") || url.startsWith("file:")) {
154-
// open dos prompt, give it 'start' command, which will
155-
// open the url properly. start by itself won't work since
156-
// it appears to need cmd
157-
Runtime.getRuntime().exec("cmd /c start \"\" \"" + url + "\"");
158-
} else {
159-
// just launching the .html file via the shell works
160-
// but make sure to chmod +x the .html files first
161-
// also place quotes around it in case there's a space
162-
// in the user.dir part of the url
163-
Runtime.getRuntime().exec("cmd /c \"" + url + "\"");
164-
}
158+
159+
// just launching the .html file via the shell works
160+
// but make sure to chmod +x the .html files first
161+
// also place quotes around it in case there's a space
162+
// in the user.dir part of the url
163+
Runtime.getRuntime().exec("cmd /c \"" + url + "\"");
165164
}
166165

167166

0 commit comments

Comments
 (0)