forked from mewbak/clipman
-
Notifications
You must be signed in to change notification settings - Fork 5
/
notify.go
43 lines (36 loc) · 849 Bytes
/
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
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
func smartLog(message, urgency string, alert bool) {
if alert {
if err := notify(message, urgency); err != nil {
log.Printf("failure sending notification: %s\n", err)
}
}
switch urgency {
case "critical", "normal":
log.Fatal(message)
default:
log.Println(message)
}
}
func notify(message, urgency string) error {
var timeout time.Duration
switch urgency {
// cases accepted by notify-send: low, normal, critical
case "critical":
timeout = 5 * time.Second
case "low":
timeout = 2 * time.Second
default:
timeout = 3 * time.Second
}
// notify-send only accepts milliseconds
millisec := fmt.Sprintf("%v", timeout.Seconds()*1000)
args := []string{"-a", "Clipman", "-u", urgency, "-t", millisec, message}
return exec.Command("notify-send", args...).Run()
}