38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
// Package browser opens a URL in the operator's default browser. It's
|
|
// a thin OS-aware wrapper around xdg-open / open / rundll32 so both
|
|
// the sherlock CLI and the MCP binaries can share the same behaviour
|
|
// without depending on each other.
|
|
package browser
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
)
|
|
|
|
// Open starts the OS's default browser pointed at url, then returns
|
|
// immediately. The browser process is reaped in a background goroutine.
|
|
// Errors come from starting the helper, not from anything the browser
|
|
// itself reports — there's no portable way to know whether the user
|
|
// actually loaded the page.
|
|
func Open(url string) error {
|
|
var bin string
|
|
var args []string
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
bin = "open"
|
|
args = []string{url}
|
|
case "windows":
|
|
bin = "rundll32"
|
|
args = []string{"url.dll,FileProtocolHandler", url}
|
|
default:
|
|
bin = "xdg-open"
|
|
args = []string{url}
|
|
}
|
|
cmd := exec.Command(bin, args...)
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
go func() { _ = cmd.Wait() }()
|
|
return nil
|
|
}
|