mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Prefer to have widgets force a draw when their data changes. This should reduce draws (unless the user has a module installed that updates >= 1/sec, the old draw default). This should also remove a source of some of the race conditions that users were experiencing (though not all, there are still many).
59 lines
960 B
Go
59 lines
960 B
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type Widget struct {
|
|
wtf.TextWidget
|
|
|
|
systemInfo *SystemInfo
|
|
Date string
|
|
Version string
|
|
}
|
|
|
|
func NewWidget(app *tview.Application, date, version string) *Widget {
|
|
widget := Widget{
|
|
TextWidget: wtf.NewTextWidget(app, "System", "system", false),
|
|
|
|
Date: date,
|
|
Version: version,
|
|
}
|
|
|
|
widget.systemInfo = NewSystemInfo()
|
|
|
|
return &widget
|
|
}
|
|
|
|
func (widget *Widget) Refresh() {
|
|
widget.UpdateRefreshedAt()
|
|
|
|
widget.View.SetText(
|
|
fmt.Sprintf(
|
|
"%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()
|
|
}
|
|
|
|
return str.Format("Jan _2, 15:04")
|
|
}
|