From 24c72570a54b7aef67494e8cacecb0a896b19886 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 15:38:40 -0600 Subject: [PATCH] more cleaning Signed-off-by: Jeff Carr --- linuxstatus/common.go | 21 +++++++++------ linuxstatus/net.go | 61 ++++++++++++++----------------------------- main.go | 26 +----------------- 3 files changed, 34 insertions(+), 74 deletions(-) diff --git a/linuxstatus/common.go b/linuxstatus/common.go index de4489e..d26b301 100644 --- a/linuxstatus/common.go +++ b/linuxstatus/common.go @@ -6,29 +6,36 @@ import ( "go.wit.com/gui/gui" ) +// reports externally if something has changed +// since the last time it was asked about it +func (ls *LinuxStatus) Changed() bool { + if ! ls.Ready() {return false} + if ls.changed { + ls.changed = false + return true + } + return false +} + func (ls *LinuxStatus) Make() { - log.Log(CHANGE, "Draw() window") if ! ls.Ready() {return} - log.Log(CHANGE, "Draw() window ready =", ls.ready) + log.Log(CHANGE, "Make() window ready =", ls.ready) ls.window.Make() ls.ready = true } func (ls *LinuxStatus) Draw() { - log.Log(CHANGE, "Draw() window") if ! ls.Ready() {return} log.Log(CHANGE, "Draw() window ready =", ls.ready) ls.window.Draw() ls.ready = true } func (ls *LinuxStatus) Draw2() { - log.Log(CHANGE, "draw(ls)") if ! ls.Ready() {return} log.Log(CHANGE, "draw(ls) ready =", ls.ready) draw(ls) } func (ls *LinuxStatus) Show() { - log.Log(CHANGE, "Show() window") if ! ls.Ready() {return} log.Log(CHANGE, "Show() window ready =", ls.ready) ls.window.Show() @@ -36,7 +43,6 @@ func (ls *LinuxStatus) Show() { } func (ls *LinuxStatus) Hide() { - log.Log(CHANGE, "Hide() window") if ! ls.Ready() {return} log.Log(CHANGE, "Hide() window ready =", ls.ready) ls.window.Hide() @@ -44,7 +50,6 @@ func (ls *LinuxStatus) Hide() { } func (ls *LinuxStatus) Toggle() { - log.Log(CHANGE, "Toggle() window") if ! ls.Ready() {return} log.Log(CHANGE, "Toggle() window ready =", ls.ready) if ls.hidden { @@ -55,7 +60,7 @@ func (ls *LinuxStatus) Toggle() { } func (ls *LinuxStatus) Ready() bool { - log.Log(CHANGE, "Ready()") + log.Log(SPEW, "Ready() maybe not ready? ls =", ls) if me == nil {return false} if ls == nil {return false} if ls.window == nil {return false} diff --git a/linuxstatus/net.go b/linuxstatus/net.go index 89f6de0..2926946 100644 --- a/linuxstatus/net.go +++ b/linuxstatus/net.go @@ -4,40 +4,12 @@ package linuxstatus import ( // "log" "net" + "sort" "strings" "go.wit.com/log" ) -// this doesn't work -/* -func watchNetworkInterfaces() { - // Get list of network interfaces - interfaces, _ := net.Interfaces() - - // Set up a notification channel - notification := make(chan net.Interface) - - log.Log(NET, "watchNet()") - // Start goroutine to watch for changes - go func() { - log.Log(NET, "watchNet() func") - for { - log.Log(NET, "forever loop start") - // Check for changes in each interface - for _, i := range interfaces { - log.Log(NET, "something on i =", i) - if status := i.Flags & net.FlagUp; status != 0 { - notification <- i - log.Log(NET, "something on i =", i) - } - } - log.Log(NET, "forever loop end") - } - }() -} -*/ - func IsIPv6(address string) bool { return strings.Count(address, ":") >= 2 } @@ -240,28 +212,35 @@ func scanInterfaces() { // displays the IP address found on your network interfaces func updateRealAAAA() { - var all4 string - var all6 string + var all4 []string + var all6 []string for s, t := range me.ipmap { if (t.ipv4) { - all4 += s + "\n" + all4 = append(all4, s) log.Log(NET, "IPv4 =", s) } else if (t.ipv6) { - all6 += s + "\n" + all6 = append(all6, s) log.Log(NET, "IPv6 =", s) } else { log.Log(NET, "???? =", s) } } - all4 = sortLines(all4) - all6 = sortLines(all6) - if (me.IPv4.Get() != all4) { - log.Log(NET, "IPv4 addresses have changed", all4) - me.IPv4.Set(all4) + + // sort and create text + sort.Strings(all4) + sort.Strings(all6) + s4 := strings.Join(all4, "\n") + s6 := strings.Join(all6, "\n") + + if (me.IPv4.Get() != s4) { + log.Log(CHANGE, "IPv4 addresses have changed", s4) + me.IPv4.Set(s4) + me.changed = true } - if (me.IPv6.Get() != all6) { - log.Log(NET, "IPv6 addresses have changed", all6) - me.IPv6.Set(all6) + if (me.IPv6.Get() != s6) { + log.Log(CHANGE, "IPv6 addresses have changed", s6) + me.IPv6.Set(s6) + me.changed = true } } diff --git a/main.go b/main.go index d7c6a93..dad92f3 100644 --- a/main.go +++ b/main.go @@ -154,38 +154,14 @@ func dnsTTL() { } func linuxLoop() { - me.changed = false - log.Log(NET, "FQDN =", me.fqdn.GetText()) - duration := timeFunction(getHostname) - log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed) - - var aaaa []string - aaaa = dhcpAAAA() - var all string - for _, s := range aaaa { - log.Log(NET, "my actual AAAA = ",s) - all += s + "\n" - } // me.IPv6.SetText(all) - if (me.changed) { + if (me.statusOS.Changed()) { stamp := time.Now().Format("2006/01/02 15:04:05") log.Log(CHANGE, "Network things changed on", stamp) duration := timeFunction(updateDNS) log.Log(CHANGE, "updateDNS() execution Time: ", duration) } - - /* - processName := getProcessNameByPort(53) - fmt.Println("Process with port 53:", processName) - - commPath := filepath.Join("/proc", proc.Name(), "comm") - comm, err := ioutil.ReadFile(commPath) - if err != nil { - return "", err // Error reading the process name - } - return strings.TrimSpace(string(comm)), nil - */ } /*