-
-
Notifications
You must be signed in to change notification settings - Fork 802
/
widget.go
64 lines (51 loc) · 1.04 KB
/
widget.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
package system
import (
"fmt"
"time"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object
var Config *config.Config
type Widget struct {
wtf.TextWidget
systemInfo *SystemInfo
Date string
Version string
}
func NewWidget(date, version string) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Build ", "system", false),
Date: date,
Version: version,
}
widget.systemInfo = NewSystemInfo()
return &widget
}
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
widget.UpdateRefreshedAt()
widget.View.Clear()
fmt.Fprintf(
widget.View,
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
"Built",
widget.prettyDate(),
"Vers",
widget.Version,
"OS",
widget.systemInfo.ProductVersion,
"Build",
widget.systemInfo.BuildVersion,
)
}
func (widget *Widget) prettyDate() string {
str, err := time.Parse(wtf.TimestampFormat, widget.Date)
if err != nil {
return err.Error()
} else {
return str.Format("Jan _2, 15:04")
}
}