-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifications.go
78 lines (61 loc) · 1.42 KB
/
notifications.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"log"
"github.com/godbus/dbus"
"github.com/TheCreeper/go-notify"
)
const (
INFO = 0
NOTICE = 1
WARNING = 2
CRITICAL = 3
)
type DesktopNotifications struct {
notifications map[string]uint32
}
func newDesktopNotifications() *DesktopNotifications {
if _, err := dbus.SessionBus(); err != nil {
log.Printf("Error enabling dbus based notifications! %+v\n", err)
return nil
}
dn := new(DesktopNotifications)
dn.notifications = make(map[string]uint32)
return dn
}
func (dn *DesktopNotifications) show(cat, message string, Priority int) error {
hints := make(map[string]interface{})
hints[notify.HintTransient] = false
hints[notify.HintActionIcons] = "NSAway"
icon := "dialog-warning"
timeout := notify.ExpiresDefault
showFullscreen := false
if Priority == NOTICE {
icon = "dialog-information"
}
if Priority == WARNING {
timeout = 15000
}
if Priority == CRITICAL {
timeout = notify.ExpiresNever
icon = "dialog-error"
showFullscreen = true
}
if showFullscreen {
hints[notify.HintUrgency] = notify.UrgencyCritical
}
notification := notify.Notification{
AppName: "EventNotifier",
AppIcon: icon,
Timeout: int32(timeout),
Hints: hints,
}
notification.Summary = "NSAway Event Notifier"
notification.Body = message
nid, err := notification.Show()
if err != nil {
return fmt.Errorf("Error showing notification: %v", err)
}
dn.notifications[cat] = nid
return nil
}