-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnotify_darwin.go
39 lines (34 loc) · 959 Bytes
/
notify_darwin.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
package notify
import (
"log"
"github.com/deckarep/gosx-notifier"
)
// Notify displays a desktop notification
func Notify(appName string, title string, text string, iconPath string) {
note := notification(appName, title, text, iconPath)
if err := note.Push(); err != nil {
log.Println("ERROR:", err)
}
}
// Alert displays a desktop notification and plays a default system sound
func Alert(appName string, title string, text string, iconPath string) {
note := notification(appName, title, text, iconPath)
note.Sound = gosxnotifier.Default
if err := note.Push(); err != nil {
log.Println("ERROR:", err)
}
}
func notification(appName string, title string, text string, iconPath string) *gosxnotifier.Notification {
head := ""
if text == "" {
head = title
title = ""
} else {
head = text
}
note := gosxnotifier.NewNotification(head)
note.Title = appName
note.Subtitle = title
note.AppIcon = iconPath // (10.9+ ONLY)
return note
}