From bb41ad791f929cdf914a6d257e3dc262def31848 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 22 May 2017 12:25:58 +0200 Subject: [PATCH] Use win32 ShellExecute API to open URL with default browser --- .../src/processing/app/windows/Platform.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index 349415b2b..2b426f728 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -37,6 +37,7 @@ import java.util.List; import com.sun.jna.Native; import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.Shell32; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; @@ -129,11 +130,15 @@ public class Platform extends processing.app.Platform { if (file.exists()) { // in this case convert the path to a "file:" url url = file.toURI().toString(); - - // this allows to open the file on Windows 10 that - // has a more strict permission policy for cmd.exe } } + if (url.startsWith("http") || url.startsWith("file:")) { + // this allows to open the file on Windows 10 that + // has a more strict permission policy for cmd.exe + final int SW_SHOW = 5; + Shell32.INSTANCE.ShellExecute(null, null, url, null, null, SW_SHOW); + return; + } // this is not guaranteed to work, because who knows if the // path will always be c:\progra~1 et al. also if the user has @@ -150,18 +155,12 @@ public class Platform extends processing.app.Platform { // "Access is denied" in both cygwin and the "dos" prompt. //Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" + // referenceFile + ".html"); - if (url.startsWith("http") || url.startsWith("file:")) { - // open dos prompt, give it 'start' command, which will - // open the url properly. start by itself won't work since - // it appears to need cmd - Runtime.getRuntime().exec("cmd /c start \"\" \"" + url + "\""); - } else { - // just launching the .html file via the shell works - // but make sure to chmod +x the .html files first - // also place quotes around it in case there's a space - // in the user.dir part of the url - Runtime.getRuntime().exec("cmd /c \"" + url + "\""); - } + + // just launching the .html file via the shell works + // but make sure to chmod +x the .html files first + // also place quotes around it in case there's a space + // in the user.dir part of the url + Runtime.getRuntime().exec("cmd /c \"" + url + "\""); }