-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtime.go
53 lines (45 loc) · 1.19 KB
/
time.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
package examples
import (
"github.com/unix-streamdeck/api"
"github.com/unix-streamdeck/streamdeckd/handlers"
"image"
"image/draw"
"log"
"time"
)
type TimeIconHandler struct {
Running bool
}
func (t *TimeIconHandler) Start(k api.Key, info api.StreamDeckInfo, callback func(image image.Image)) {
t.Running = true
go timeLoop(k, info, callback, t)
}
func (t *TimeIconHandler) IsRunning() bool {
return t.Running
}
func (t *TimeIconHandler) SetRunning(running bool) {
t.Running = running
}
func (t *TimeIconHandler) Stop() {
t.Running = false
}
func timeLoop(k api.Key, info api.StreamDeckInfo, callback func(image image.Image), handler *TimeIconHandler) {
for handler.Running {
img := image.NewRGBA(image.Rect(0, 0, info.IconSize, info.IconSize))
draw.Draw(img, img.Bounds(), image.Black, image.ZP, draw.Src)
t := time.Now()
tString := t.Format("15:04:05")
imgParsed, err := api.DrawText(img, tString, k.TextSize, k.TextAlignment)
if err != nil {
log.Println(err)
} else {
callback(imgParsed)
}
time.Sleep(time.Second)
}
}
func RegisterTime() handlers.Module {
return handlers.Module{NewIcon: func() api.IconHandler {
return &TimeIconHandler{Running: true}
}, Name: "Time"}
}