-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 loc) · 1.03 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
package main
import (
"fmt"
"os"
"path"
"time"
"./waniclient"
"github.com/TheCreeper/go-notify"
"github.com/kardianos/osext"
)
var clientAPIKey string
var client *waniclient.WaniClient
var notificationID uint32
func checkQueue() {
queue := client.GetStudyQueue()
if queue != nil && queue.Reviews > 0 {
folderPath, _ := osext.ExecutableFolder()
ntf := notify.NewNotification("WaniKani", fmt.Sprintf("<b>%d</b> reviews available!", queue.Reviews))
ntf.AppName = "WaniKani-notify"
ntf.ReplacesID = notificationID
ntf.AppIcon = path.Join(folderPath, "wanikani.ico")
ntf.Actions = append(ntf.Actions, "default", "default")
ntf.Hints = make(map[string]interface{})
notificationID, _ = ntf.Show()
}
}
func main() {
args := os.Args[1:]
if len(args) != 1 {
panic("Incorrect number of arguments.")
}
clientAPIKey = args[0]
client = waniclient.NewClient(clientAPIKey)
checkQueue()
timer := time.NewTicker(time.Second * 10)
go func() {
for range timer.C {
checkQueue()
}
}()
for {
time.Sleep(time.Second)
}
}