-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (64 loc) · 1.5 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
package main
/* A simple cross-platform pomodoro timer sitting in the systray */
import (
"gerymate/pomodoro/icon"
"fmt"
"time"
"github.com/getlantern/systray"
"github.com/ncruces/zenity"
)
func main() {
systray.Run(onReady, onExit)
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Pomodoro Timer")
systray.SetTooltip("Limit yourself to stay efficient")
mPom := systray.AddMenuItem("Start pomodoro", "Start a 25 minutes focus period")
mBreak := systray.AddMenuItem("Start break", "Start a short break")
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
go func() {
<-mQuit.ClickedCh
fmt.Println("Goodbye!")
systray.Quit()
}()
go func() {
for {
select {
case <-mPom.ClickedCh:
fmt.Println("Clicked Pomodoro")
pomodoro("Pomodoro - 25 minutes", "Focus...", 25*60)
case <-mBreak.ClickedCh:
fmt.Println("Clicked Break")
pomodoro("Pomodoro - 5 minutes", "Take a break!", 5*60)
}
}
}()
}
func pomodoro(title string, text string, length int) {
dlg, err := zenity.Progress(
zenity.Title(title))
if err != nil {
return
}
defer dlg.Close()
dlg.Text(text)
isClosedCh := dlg.Done()
for elapsed := 0; elapsed < length; elapsed++ {
select {
case _, ok := <-isClosedCh:
if !ok { // dialog already closed
return
}
default:
var value float32 = float32(elapsed) / float32(length) * 100
dlg.Value(int(value))
time.Sleep(time.Second)
}
}
dlg.Complete()
time.Sleep(time.Second)
}
func onExit() {
// clean up here
}