xdg-open() for buttons
This commit is contained in:
parent
732102f794
commit
79d5ca71a8
|
@ -0,0 +1,42 @@
|
|||
package shell
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// openBrowser opens the specified URL in the default browser of the user.
|
||||
func OpenBrowser(url string) error {
|
||||
var cmd string
|
||||
var args []string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
cmd = "cmd"
|
||||
args = []string{"/c", "start"}
|
||||
case "darwin":
|
||||
cmd = "open"
|
||||
default: // "linux", "freebsd", "openbsd", "netbsd"
|
||||
cmd = "xdg-open"
|
||||
}
|
||||
args = append(args, url)
|
||||
return exec.Command(cmd, args...).Start()
|
||||
}
|
||||
|
||||
func Xterm(cmd string) {
|
||||
var tmp []string
|
||||
var argsXterm = []string{"nohup", "xterm", "-geometry", "120x40"}
|
||||
/*
|
||||
if xtermHold.Checked() {
|
||||
log.Println("hold = true")
|
||||
argsXterm = append(argsXterm, "-hold")
|
||||
} else {
|
||||
log.Println("hold = false")
|
||||
}
|
||||
*/
|
||||
tmp = append(argsXterm, "-e", cmd)
|
||||
log.Info("xterm cmd=", tmp)
|
||||
go Run(tmp)
|
||||
}
|
11
run.go
11
run.go
|
@ -68,10 +68,17 @@ func RunPath(path string, args []string) bool {
|
|||
cmd.Dir = path
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
println("path =", path, "cmd =", strings.Join(args, " "))
|
||||
log.Info("path =", path, "cmd =", strings.Join(args, " "))
|
||||
if err := cmd.Run(); err != nil {
|
||||
// Handle error if the command execution fails
|
||||
println("Error executing command:", err.Error())
|
||||
log.Info("RunPath() failed")
|
||||
// log.Info("cmd.Enviorn =", cmd.Environ())
|
||||
out, outerr := cmd.Output()
|
||||
log.Info("cmd.output =", out)
|
||||
log.Info("cmd.output err=", outerr)
|
||||
log.Info("path =", path)
|
||||
log.Info("args =", args)
|
||||
log.Info("err =", err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue