-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (56 loc) · 1.31 KB
/
main.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
package main
import (
"github.com/dakyskye/github-trayer/assets"
"github.com/dakyskye/github-trayer/notification"
"github.com/getlantern/systray"
"log"
"os"
"time"
)
const title = "GitHub Trayer"
func main() {
if len(os.Args) == 1 {
log.Println("please provide your token as an argument")
os.Exit(1)
}
systray.Run(onReady, nil)
}
func onReady() {
systray.SetTemplateIcon(assets.IconDark, assets.IconDark)
systray.SetIcon(assets.IconDark)
systray.SetTitle(title)
systray.SetTooltip(title)
notif := notification.New(
title,
notification.NotificationIconPath{
Light: "assets/github_mark_plus_light.png",
Dark: "assets/github_mark_plus.png",
},
time.Second*12,
os.Args[1],
)
notifChan := notif.Subscribe()
refreshChan := systray.AddMenuItem("Refresh", "Refresh notifications count").ClickedCh
quitChan := systray.AddMenuItem("Quit", "Quit "+title).ClickedCh
for {
select {
case <-notifChan:
err := notif.NotifyIfChanged(true)
if err != nil {
log.Println("failed to send a notification", err)
}
case <-refreshChan:
err := notif.Fetch()
if err != nil {
log.Println("failed to fetch notifications", err)
continue
}
err = notif.Notify(true)
if err != nil {
log.Println("failed to send a notification", err)
}
case <-quitChan:
systray.Quit()
}
}
}