summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 15:38:40 -0600
committerJeff Carr <[email protected]>2024-01-06 15:38:40 -0600
commitc6dbbc35425de892f4e853bdc7cdd0a4d31349b3 (patch)
tree66f3388f04ecd4986a94336bb924086292030306
parentf89ba90467d8898f957722b588b697f51053fc94 (diff)
more cleaning
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--linuxstatus/common.go21
-rw-r--r--linuxstatus/net.go61
2 files changed, 33 insertions, 49 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
}
}