mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
da20785685
Former-commit-id: 23f542f43b4b493e38f5aa4c29788ed93a63b43b [formerly 71b23a6a28eb045fcfeab6329de69f1e5455486b] Former-commit-id: d12b3a6decc876f010a71f98e11df7387c1aaf2a
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package browser provides utilities for interacting with users' browsers.
|
|
package browser
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
)
|
|
|
|
// Commands returns a list of possible commands to use to open a url.
|
|
func Commands() [][]string {
|
|
var cmds [][]string
|
|
if exe := os.Getenv("BROWSER"); exe != "" {
|
|
cmds = append(cmds, []string{exe})
|
|
}
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
cmds = append(cmds, []string{"/usr/bin/open"})
|
|
case "windows":
|
|
cmds = append(cmds, []string{"cmd", "/c", "start"})
|
|
default:
|
|
cmds = append(cmds, []string{"xdg-open"})
|
|
}
|
|
cmds = append(cmds,
|
|
[]string{"chrome"},
|
|
[]string{"google-chrome"},
|
|
[]string{"chromium"},
|
|
[]string{"firefox"},
|
|
)
|
|
return cmds
|
|
}
|
|
|
|
// Open tries to open url in a browser and reports whether it succeeded.
|
|
func Open(url string) bool {
|
|
for _, args := range Commands() {
|
|
cmd := exec.Command(args[0], append(args[1:], url)...)
|
|
if cmd.Start() == nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|