more cleaning

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-06 15:38:40 -06:00
parent f89ba90467
commit c6dbbc3542
2 changed files with 33 additions and 49 deletions

View File

@ -6,29 +6,36 @@ import (
"go.wit.com/gui/gui" "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() { func (ls *LinuxStatus) Make() {
log.Log(CHANGE, "Draw() window")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "Draw() window ready =", ls.ready) log.Log(CHANGE, "Make() window ready =", ls.ready)
ls.window.Make() ls.window.Make()
ls.ready = true ls.ready = true
} }
func (ls *LinuxStatus) Draw() { func (ls *LinuxStatus) Draw() {
log.Log(CHANGE, "Draw() window")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "Draw() window ready =", ls.ready) log.Log(CHANGE, "Draw() window ready =", ls.ready)
ls.window.Draw() ls.window.Draw()
ls.ready = true ls.ready = true
} }
func (ls *LinuxStatus) Draw2() { func (ls *LinuxStatus) Draw2() {
log.Log(CHANGE, "draw(ls)")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "draw(ls) ready =", ls.ready) log.Log(CHANGE, "draw(ls) ready =", ls.ready)
draw(ls) draw(ls)
} }
func (ls *LinuxStatus) Show() { func (ls *LinuxStatus) Show() {
log.Log(CHANGE, "Show() window")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "Show() window ready =", ls.ready) log.Log(CHANGE, "Show() window ready =", ls.ready)
ls.window.Show() ls.window.Show()
@ -36,7 +43,6 @@ func (ls *LinuxStatus) Show() {
} }
func (ls *LinuxStatus) Hide() { func (ls *LinuxStatus) Hide() {
log.Log(CHANGE, "Hide() window")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "Hide() window ready =", ls.ready) log.Log(CHANGE, "Hide() window ready =", ls.ready)
ls.window.Hide() ls.window.Hide()
@ -44,7 +50,6 @@ func (ls *LinuxStatus) Hide() {
} }
func (ls *LinuxStatus) Toggle() { func (ls *LinuxStatus) Toggle() {
log.Log(CHANGE, "Toggle() window")
if ! ls.Ready() {return} if ! ls.Ready() {return}
log.Log(CHANGE, "Toggle() window ready =", ls.ready) log.Log(CHANGE, "Toggle() window ready =", ls.ready)
if ls.hidden { if ls.hidden {
@ -55,7 +60,7 @@ func (ls *LinuxStatus) Toggle() {
} }
func (ls *LinuxStatus) Ready() bool { func (ls *LinuxStatus) Ready() bool {
log.Log(CHANGE, "Ready()") log.Log(SPEW, "Ready() maybe not ready? ls =", ls)
if me == nil {return false} if me == nil {return false}
if ls == nil {return false} if ls == nil {return false}
if ls.window == nil {return false} if ls.window == nil {return false}

View File

@ -4,40 +4,12 @@ package linuxstatus
import ( import (
// "log" // "log"
"net" "net"
"sort"
"strings" "strings"
"go.wit.com/log" "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 { func IsIPv6(address string) bool {
return strings.Count(address, ":") >= 2 return strings.Count(address, ":") >= 2
} }
@ -240,28 +212,35 @@ func scanInterfaces() {
// displays the IP address found on your network interfaces // displays the IP address found on your network interfaces
func updateRealAAAA() { func updateRealAAAA() {
var all4 string var all4 []string
var all6 string var all6 []string
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.ipv4) { if (t.ipv4) {
all4 += s + "\n" all4 = append(all4, s)
log.Log(NET, "IPv4 =", s) log.Log(NET, "IPv4 =", s)
} else if (t.ipv6) { } else if (t.ipv6) {
all6 += s + "\n" all6 = append(all6, s)
log.Log(NET, "IPv6 =", s) log.Log(NET, "IPv6 =", s)
} else { } else {
log.Log(NET, "???? =", s) log.Log(NET, "???? =", s)
} }
} }
all4 = sortLines(all4)
all6 = sortLines(all6) // sort and create text
if (me.IPv4.Get() != all4) { sort.Strings(all4)
log.Log(NET, "IPv4 addresses have changed", all4) sort.Strings(all6)
me.IPv4.Set(all4) 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) { if (me.IPv6.Get() != s6) {
log.Log(NET, "IPv6 addresses have changed", all6) log.Log(CHANGE, "IPv6 addresses have changed", s6)
me.IPv6.Set(all6) me.IPv6.Set(s6)
me.changed = true
} }
} }