-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
77 lines (60 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/getlantern/systray"
"github.com/goodsign/monday"
)
var (
sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built
semVer string // the version of the build
)
func main() {
enableDpiAwareness()
systray.Run(onReady, func() {})
}
var menus []*systray.MenuItem
func onReady() {
systray.SetTitle("Kalenderwoche")
const numberOfEntries = 15
addMenuItemsForUpcomingCalendarWeekDates(numberOfEntries)
go keepWeekNumberIconUpToDate()
go quitOnMenu()
}
func addMenuItemsForUpcomingCalendarWeekDates(numberOfEntries int) {
for i := 0; i < numberOfEntries; i++ {
index := i
menus = append(menus, systray.AddMenuItem("refresh", ""))
go func() {
for {
<-menus[index].ClickedCh
_, dateToGo := offsetCalendarWeekToDate(index)
goToDate(dateToGo)
}
}()
}
systray.AddSeparator()
}
func keepWeekNumberIconUpToDate() {
calendarWeek := currentCalendarWeekIterator()
for {
updateIconAndTooltip(<-calendarWeek.ChangedCh)
}
}
func quitOnMenu() {
quitMenuItem := systray.AddMenuItem(fmt.Sprintf("Beenden (%s - %s)", semVer, sha1ver), "Beendet die Applikation")
<-quitMenuItem.ClickedCh
systray.Quit()
}
func updateIconAndTooltip(weekNumber int) {
systray.SetIcon(generateImage(weekNumber))
systray.SetTooltip(fmt.Sprintf("Aktuelle Kalenderwoche: %d", weekNumber))
refreshUpcomingCalendarWeekItems()
}
func refreshUpcomingCalendarWeekItems() {
for index, _ := range menus {
week, startDate := offsetCalendarWeekToDate(index)
text := fmt.Sprintf("KW %d: %s", week, monday.Format(startDate, "02. January 2006", monday.LocaleDeDE))
menus[index].SetTitle(text)
}
}