You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-29 16:58:00 +02:00
added ServeEvent.InstallerFunc field
This commit is contained in:
31
tools/osutils/cmd.go
Normal file
31
tools/osutils/cmd.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package osutils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/go-ozzo/ozzo-validation/v4/is"
|
||||
)
|
||||
|
||||
// LaunchURL attempts to open the provided url in the user's default browser.
|
||||
//
|
||||
// It is platform dependent and it uses:
|
||||
// - "open" on macOS
|
||||
// - "rundll32" on Windows
|
||||
// - "xdg-open" on everything else (Linux, FreeBSD, etc.)
|
||||
func LaunchURL(url string) error {
|
||||
if err := is.URL.Validate(url); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return exec.Command("open", url).Start()
|
||||
case "windows":
|
||||
// not sure if this is the best command but seems to be the most reliable based on the comments in
|
||||
// https://stackoverflow.com/questions/3739327/launching-a-website-via-the-windows-commandline#answer-49115945
|
||||
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||
default:
|
||||
return exec.Command("xdg-open", url).Start()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user