forked from zserge/lorca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagebox.go
33 lines (30 loc) · 870 Bytes
/
messagebox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//+build !windows
package lorca
import (
"fmt"
"os/exec"
"runtime"
"strings"
"syscall"
)
func messageBox(title, text string) bool {
if runtime.GOOS == "linux" {
err := exec.Command("zenity", "--question", "--title", title, "--text", text).Run()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
return exitError.Sys().(syscall.WaitStatus).ExitStatus() == 0
}
}
} else if runtime.GOOS == "darwin" {
script := `set T to button returned of ` +
`(display dialog "%s" with title "%s" buttons {"No", "Yes"} default button "Yes")`
out, err := exec.Command("osascript", "-e", fmt.Sprintf(script, text, title)).Output()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
return exitError.Sys().(syscall.WaitStatus).ExitStatus() == 0
}
}
return strings.TrimSpace(string(out)) == "Yes"
}
return false
}