-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify.go
63 lines (52 loc) · 1.21 KB
/
notify.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ppow
import (
"fmt"
"os/exec"
)
const prog = "ppow"
func hasExecutable(name string) bool {
_, err := exec.LookPath(name)
if err != nil {
return false
}
return true
}
// A Notifier notifies
type Notifier interface {
Push(title string, content string, icon string)
}
// BeepNotifier just emits a beep on the terminal
type BeepNotifier struct{}
// Push implements Notifier
func (*BeepNotifier) Push(string, string, string) {
fmt.Print("\a")
}
// GrowlNotifier is a notifier for Growl
type GrowlNotifier struct {
}
// Push implements Notifier
func (GrowlNotifier) Push(title string, text string, iconPath string) {
cmd := exec.Command(
"growlnotify", "-n", prog, "-d", prog, "-m", text, prog,
)
go cmd.Run()
}
// LibnotifyNotifier is a notifier for lib-notify
type LibnotifyNotifier struct {
}
// Push implements Notifier
func (LibnotifyNotifier) Push(title string, text string, iconPath string) {
cmd := exec.Command(
"notify-send", prog, text,
)
go cmd.Run()
}
// PlatformNotifier finds a notifier for this platform
func PlatformNotifier() Notifier {
if hasExecutable("growlnotify") {
return &GrowlNotifier{}
} else if hasExecutable("notify-send") {
return &LibnotifyNotifier{}
}
return nil
}