From 36544d813ae3d14920f41c91e5cce83cd03c99ad Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Mon, 22 Apr 2024 10:23:09 -0600 Subject: [PATCH] add uptime to display --- flake.lock | 6 +++--- flake.nix | 1 + main.go | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 19c81fd..83f6135 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1711333969, - "narHash": "sha256-5PiWGn10DQjMZee5NXzeA6ccsv60iLu+Xtw+mfvkUAs=", + "lastModified": 1713714899, + "narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "57e6b3a9e4ebec5aa121188301f04a6b8c354c9b", + "rev": "6143fc5eeb9c4f00163267708e26191d1e918932", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 37a04a6..cee2fa9 100644 --- a/flake.nix +++ b/flake.nix @@ -71,6 +71,7 @@ go gopls go-tools + nilaway glfw pkg-config diff --git a/main.go b/main.go index abd68f8..d5a9afb 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ type Status struct { Host string `json:"host"` Port int32 `json:"port"` Uname string `json:"uname_a"` + Uptime string `json:"uptime"` } type Config struct { @@ -307,7 +308,7 @@ func (s *Status) ToTable() *widget.Table { t := widget.NewTable( // Length func() (int, int) { - return 6, 2 + return 7, 2 }, // CreateCell func() fyne.CanvasObject { @@ -329,10 +330,12 @@ func (s *Status) ToTable() *widget.Table { case 2: content.SetText("Uname") case 3: - content.SetText("Configuration Revision") + content.SetText("Uptime") case 4: - content.SetText("Restart?") + content.SetText("Configuration Revision") case 5: + content.SetText("Restart?") + case 6: content.SetText("System Diff") } } @@ -345,14 +348,16 @@ func (s *Status) ToTable() *widget.Table { case 2: content.SetText(s.Uname) case 3: - content.SetText(s.ConfigurationRevision) + content.SetText(s.Uptime) case 4: + content.SetText(s.ConfigurationRevision) + case 5: str := "No" if s.NeedsRestart { str = "Yes" } content.SetText(str) - case 5: + case 6: text, err := base64.StdEncoding.DecodeString(s.SystemDiff) if err != nil { fmt.Println("decode error:", err) @@ -373,7 +378,7 @@ func (s *Status) ToTable() *widget.Table { t.SetColumnWidth(0, 300.0) t.SetColumnWidth(1, 600.0) - t.SetRowHeight(5, 600.0) + t.SetRowHeight(6, 600.0) return t } @@ -390,17 +395,22 @@ func buildCards(stat *xinStatus) fyne.CanvasObject { verBStr := binding.BindString(&s.NixosVersion) bvl := widget.NewLabelWithData(verBStr) + uptimeBStr := binding.BindString(&s.Uptime) + uvl := widget.NewLabelWithData(uptimeBStr) + restartBBool := binding.BindBool(&s.NeedsRestart) bbl := widget.NewCheckWithData("Reboot", restartBBool) bbl.Disable() stat.boundStrings = append(stat.boundStrings, commitBStr) stat.boundStrings = append(stat.boundStrings, verBStr) + stat.boundStrings = append(stat.boundStrings, uptimeBStr) stat.boundBools = append(stat.boundBools, restartBBool) card := widget.NewCard(s.Host, "", container.NewVBox( container.NewHBox(bvl), + container.NewHBox(uvl), container.NewHBox(bbl), container.NewHBox(bsl), ),