From ba3d5a3cb24429692a1d799e73a9d53cc798212e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 14:23:19 -0600 Subject: [PATCH] more isolation of Update() pieces Signed-off-by: Jeff Carr --- gui.go | 12 ++++----- hostnameStatus.go | 2 +- linuxstatus/hostname.go | 55 ++++++++++++++++++++++++++--------------- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/gui.go b/gui.go index 3f7fd10..c988ab4 100644 --- a/gui.go +++ b/gui.go @@ -44,7 +44,7 @@ func detailsTab(title string) { // me.domainname = grid.NewLabel("domainname") grid.NewLabel("hostname -s =") - me.hostshort = grid.NewLabel("hostname -s") + grid.NewLabel("DEPRECATED") grid.NewLabel("NS records =") me.NSrr = grid.NewLabel("NS RR's") @@ -227,17 +227,17 @@ func mainWindow(title string) { me.details.Toggle() }) gr.NewButton("linuxstatus.New()", func () { - me.statusOS = linuxstatus.New() + if (me.statusOS == nil) { + me.statusOS = linuxstatus.New() + } me.statusOS.SetParent(me.myGui) me.statusOS.InitWindow() + me.statusOS.Make() + me.statusOS.Draw2() }) gr.NewButton("statusOS.Ready()", func () { me.statusOS.Ready() }) - gr.NewButton("statusOS.Make()", func () { - me.statusOS.Make() - me.statusOS.Draw2() - }) gr.NewButton("statusOS.Draw()", func () { me.statusOS.Draw() me.statusOS.Draw2() diff --git a/hostnameStatus.go b/hostnameStatus.go index bc13f6a..87347db 100644 --- a/hostnameStatus.go +++ b/hostnameStatus.go @@ -296,7 +296,7 @@ func (hs *hostnameStatus) updateStatus() { var vals []string log.Log(STATUS, "updateStatus() START") - hs.hostShort.Set(me.hostshort.S) + hs.hostShort.Set(me.statusOS.GetHostShort()) hs.domainname.Set(me.statusOS.GetDomainName()) if hs.ValidHostname() { diff --git a/linuxstatus/hostname.go b/linuxstatus/hostname.go index 6853ba6..08c7971 100644 --- a/linuxstatus/hostname.go +++ b/linuxstatus/hostname.go @@ -22,9 +22,41 @@ func (ls *LinuxStatus) GetDomainName() string { return me.domainname.Get() } -func (ls *LinuxStatus) setDomainName(dn string) { +func (ls *LinuxStatus) setDomainName() { if ! me.Ready() {return} - me.domainname.Set(dn) + + dn := run("domainname") + if me.window == nil { + log.Log(NOW, "me.window == nil") + } else { + log.Log(NOW, "me.window exists, but has not been drawn") + log.Log(NOW, "me.window.Draw() =") + } + if (me.domainname.Get() != dn) { + log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn) + me.domainname.Set(dn) + me.changed = true + } +} + +func (ls *LinuxStatus) GetHostShort() string { + if ! me.Ready() {return ""} + if me.window == nil { + log.Log(NOW, "me.window == nil") + } else { + log.Log(NOW, "me.window exists, but has not been drawn") + } + return me.hostshort.Get() +} + +func (ls *LinuxStatus) setHostShort() { + if ! me.Ready() {return ""} + hshort := run("hostname -s") + if (me.hostshort.Get() != hshort) { + log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort) + me.hostshort.Set(hshort) + me.changed = true + } } func lookupHostname() { @@ -38,25 +70,8 @@ func lookupHostname() { } log.Error(errors.New("full hostname should be: " + s)) - dn := run("domainname") - if me.window == nil { - log.Log(NOW, "me.window == nil") - } else { - log.Log(NOW, "me.window exists, but has not been drawn") - log.Log(NOW, "me.window.Draw() =") - } - if (me.domainname.Get() != dn) { - log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn) - me.setDomainName(dn) - me.changed = true - } + me.setDomainName() - hshort := run("hostname -s") - if (me.hostshort.Get() != hshort) { - log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort) - me.hostshort.Set(hshort) - me.changed = true - } /* var test string