### Purpose
On Windows replace `cmd.exe /C start` with direct `ShellExecute` API for
opening the webpage.
The previous implementation used `exec.Command("cmd.exe", "/C", "start
"+url)` which spawns two extra processes (cmd.exe → start). Launching
cmd.exe resulted in a shortly visible terminal.
Both
-`start`
-and another alternative `exec.Command("rundll32",
"url.dll,FileProtocolHandler", url).Start()`
are just wrappers for `ShellExecute`. So this implementation is even
more direct
### Testing
I executed the compiled syncthing.exe on Windows 11, both from explorer
and console. The webpage opened as expected.
### Screenshots
N/A.
### Documentation
N/A
## Authorship
Name: Elias @Shablone
Email: [1elias.bauer@gmail.com](mailto:1elias.bauer@gmail.com)
Signed-off-by: Elias <1elias.bauer@gmail.com>
Co-authored-by: Elias <1elias.bauer@gmail.com>
36 lines
723 B
Go
36 lines
723 B
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
//go:build windows
|
|
// +build windows
|
|
|
|
package main
|
|
|
|
import "golang.org/x/sys/windows"
|
|
|
|
func openURL(url string) error {
|
|
urlPtr, err := windows.UTF16PtrFromString(url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
verbPtr, err := windows.UTF16PtrFromString("open")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = windows.ShellExecute(
|
|
0, // hwnd
|
|
verbPtr, // operation
|
|
urlPtr, // file
|
|
nil, // parameters
|
|
nil, // directory
|
|
windows.SW_SHOWNORMAL,
|
|
)
|
|
|
|
return err
|
|
}
|