/
timeNotifier.go
76 lines (67 loc) · 1.34 KB
/
timeNotifier.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
package main
import (
"log"
"os"
"time"
"github.com/veandco/go-sdl2/sdl"
)
//TNotifier mode
type TNotifier struct {
App *Application
Alias string
}
//SetApp interface method
func (tn *TNotifier) SetApp(app *Application) {
tn.App = app
tn.Alias = "\uf017"
}
//GetAlias interface method
func (tn *TNotifier) GetAlias() string {
return tn.Alias
}
//Init interface method
func (tn *TNotifier) Init() WidgetSettings {
app := tn.App
window := tn.App.Window
fontSize = 14
w := 500
h := (fontSize + 10) * 13
window, err := sdl.CreateWindow("Shadow", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
w, h, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
app.Window = window
return WidgetSettings{fontSize, Geometry{int32(w), int32(h)}, Padding{10, 30, 10}}
}
//Draw interface method
func (tn *TNotifier) Draw() {
c := make(chan Line)
go GetTime(c)
app := tn.App
T := app.Widget
T.Reset()
T.App.DrawMode()
for {
ret := <-c
if ret.Content == "end" {
break
}
T.AddLine(ret)
}
go func() {
time.Sleep(5 * time.Second)
if app.Mode == "time" {
log.Println(os.Remove("/tmp/shadow.lock"))
os.Exit(0)
}
}()
}
//DispatchEvents interface method
func (tn *TNotifier) DispatchEvents(event sdl.Event) int {
return 1
}
//DispatchKeys interface method
func (tn *TNotifier) DispatchKeys(event *sdl.KeyDownEvent) int {
return 1
}