forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (68 loc) · 1.61 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"
"runtime"
"time"
"github.com/progrium/macdriver/cocoa"
"github.com/progrium/macdriver/objc"
)
func main() {
runtime.LockOSThread()
app := cocoa.NSApp_WithDidLaunch(func(n objc.Object) {
obj := cocoa.NSStatusBar_System().StatusItemWithLength(cocoa.NSVariableStatusItemLength)
obj.Retain()
obj.Button().SetTitle("▶️ Ready")
nextClicked := make(chan bool)
go func() {
state := -1
timer := 1500
countdown := false
for {
select {
case <-time.After(1 * time.Second):
if timer > 0 && countdown {
timer = timer - 1
}
if timer <= 0 && state%2 == 1 {
state = (state + 1) % 4
}
case <-nextClicked:
state = (state + 1) % 4
timer = map[int]int{
0: 1500,
1: 1500,
2: 0,
3: 300,
}[state]
if state%2 == 1 {
countdown = true
} else {
countdown = false
}
}
labels := map[int]string{
0: "▶️ Ready %02d:%02d",
1: "✴️ Working %02d:%02d",
2: "✅ Finished %02d:%02d",
3: "⏸️ Break %02d:%02d",
}
obj.Button().SetTitle(fmt.Sprintf(labels[state], timer/60, timer%60))
}
}()
nextClicked <- true
itemNext := cocoa.NSMenuItem_New()
itemNext.SetTitle("Next")
itemNext.SetAction(objc.Sel("nextClicked:"))
cocoa.DefaultDelegateClass.AddMethod("nextClicked:", func(_ objc.Object) {
nextClicked <- true
})
itemQuit := cocoa.NSMenuItem_New()
itemQuit.SetTitle("Quit")
itemQuit.SetAction(objc.Sel("terminate:"))
menu := cocoa.NSMenu_New()
menu.AddItem(itemNext)
menu.AddItem(itemQuit)
obj.SetMenu(menu)
})
app.Run()
}