-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (45 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
60 lines (45 loc) · 1.29 KB
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
package main
import (
"flag"
"os"
"strings"
"time"
"github.com/gen2brain/beeep"
)
func main() {
timeSeconds := flag.Int("s", 0, "Timer seconds duration")
timeMinutes := flag.Int("m", 0, "Timer minutes duration")
timeHours := flag.Int("h", 0, "Timer hours duration")
timeString := flag.String("t", "", "Specific time. e.g.: 15:04:05")
title := flag.String("title", "Time's up!", "Notification title")
message := flag.String("msg", "", "Notification message")
flag.Parse()
var timer *time.Timer
if *timeString != "" {
if strings.Count(*timeString, ":") == 1 {
*timeString = *timeString + ":00"
}
targetTime, err := time.Parse(time.TimeOnly, *timeString)
if err != nil {
panic(err)
}
now := time.Now()
targetTime = time.Date(
now.Year(), now.Month(), now.Day(),
targetTime.Hour(), targetTime.Minute(), targetTime.Second(),
0, now.Location(),
)
timer = time.NewTimer(time.Until(targetTime))
} else if *timeSeconds > 0 || *timeMinutes > 0 || *timeHours > 0 {
timer = time.NewTimer(time.Duration(*timeSeconds)*time.Second + time.Duration(*timeMinutes)*time.Minute + time.Duration(*timeHours)*time.Hour)
}
if timer == nil {
os.Exit(1)
}
<-timer.C
beeep.AppName = "Timer"
err := beeep.Notify(*title, *message, "stopwatch")
if err != nil {
panic(err)
}
}