Skip to content

Commit 28dca72

Browse files
author
Steven Penny
committed
Windows: utilize ShellExecuteW
On Windows, use the `ShellExecuteW` syscall instead of an external command. The `HideWindow` option is no longer configurable, as `setFlags` assumes an external command is to be run. Long term, would be better to refactor the package, as different Window behavior can be configured via the last argument to `ShellExecuteW` (`nShowCmd`). https://docs.microsoft.com/windows/win32/api/shellapi/nf-shellapi-shellexecutew Fixes pkg#16
1 parent 0426ae3 commit 28dca72

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

browser_windows.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
//go:generate mkwinsyscall -output zbrowser_windows.go browser_windows.go
2+
//sys ShellExecute(hwnd int, verb string, file string, args string, cwd string, showCmd int) (err error) = shell32.ShellExecuteW
13
package browser
24

3-
import (
4-
"os/exec"
5-
"strings"
6-
"syscall"
7-
)
5+
import "os/exec"
6+
const SW_SHOWNORMAL = 1
87

98
func openBrowser(url string) error {
10-
r := strings.NewReplacer("&", "^&")
11-
return runCmd("cmd", "/c", "start", r.Replace(url))
9+
return ShellExecute(0, "", url, "", "", SW_SHOWNORMAL)
1210
}
1311

1412
func setFlags(cmd *exec.Cmd) {
15-
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
1613
}

zbrowser_windows.go

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)