mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Closes #32. OS version and build info into System module
This commit is contained in:
parent
5353d6ddf7
commit
06702835f3
33
system/system_info.go
Normal file
33
system/system_info.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SystemInfo struct {
|
||||||
|
ProductName string
|
||||||
|
ProductVersion string
|
||||||
|
BuildVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSystemInfo(raw string) *SystemInfo {
|
||||||
|
m := make(map[string]string)
|
||||||
|
|
||||||
|
for _, row := range strings.Split(raw, "\n") {
|
||||||
|
parts := strings.Split(row, ":")
|
||||||
|
|
||||||
|
if len(parts) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
sysInfo := SystemInfo{
|
||||||
|
ProductName: m["ProductName"],
|
||||||
|
ProductVersion: m["ProductVersion"],
|
||||||
|
BuildVersion: m["BuildVersion"],
|
||||||
|
}
|
||||||
|
|
||||||
|
return &sysInfo
|
||||||
|
}
|
@ -2,6 +2,7 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
@ -14,17 +15,21 @@ var Config *config.Config
|
|||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
BuiltAt string
|
systemInfo *SystemInfo
|
||||||
Version string
|
BuiltAt string
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(builtAt, version string) *Widget {
|
func NewWidget(builtAt, version string) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" Build ", "system", false),
|
TextWidget: wtf.NewTextWidget(" Build ", "system", false),
|
||||||
BuiltAt: builtAt,
|
|
||||||
Version: version,
|
BuiltAt: builtAt,
|
||||||
|
Version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.buildSystemInfo()
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +42,15 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
widget.View,
|
widget.View,
|
||||||
"%6s: %s\n%6s: %s",
|
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
|
||||||
"Built",
|
"Built",
|
||||||
widget.prettyBuiltAt(),
|
widget.prettyBuiltAt(),
|
||||||
"Vers",
|
"Vers",
|
||||||
widget.Version,
|
widget.Version,
|
||||||
|
"OS",
|
||||||
|
widget.systemInfo.ProductVersion,
|
||||||
|
"Build",
|
||||||
|
widget.systemInfo.BuildVersion,
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
@ -55,3 +64,12 @@ func (widget *Widget) prettyBuiltAt() string {
|
|||||||
return str.Format("Jan _2, 15:04")
|
return str.Format("Jan _2, 15:04")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) buildSystemInfo() {
|
||||||
|
arg := []string{}
|
||||||
|
|
||||||
|
cmd := exec.Command("sw_vers", arg...)
|
||||||
|
str := wtf.ExecuteCommand(cmd)
|
||||||
|
|
||||||
|
widget.systemInfo = NewSystemInfo(str)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user