Compare commits

...

5 Commits

Author SHA1 Message Date
Jeff Carr 34569cbcee main window is pretty clean
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 12:45:01 -06:00
Jeff Carr 6916a6428d error button disables
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:52:15 -06:00
Jeff Carr f10c3085c6 the thing works pretty well if you use cloudflare
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:32:43 -06:00
Jeff Carr 937f77b355 delete works
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:23:51 -06:00
Jeff Carr ef6eb7a96a error window v0.1
error box starts doing something
    start a window for errors to fix
    more status cleanups & housecleaning

    Signed-off-by: Jeff Carr <jcarr@wit.com>

Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 10:38:17 -06:00
15 changed files with 285 additions and 254 deletions

View File

@ -16,7 +16,6 @@ import (
"os"
"fmt"
"time"
"strings"
"reflect"
"errors"
@ -153,6 +152,7 @@ func (ds *digStatus) setIPv6status(s string) {
me.digStatus.set(ds.statusAAAA, s)
}
/*
func (ds *digStatus) SetIPv6(s string) {
if ! ds.Ready() {return}
log.Warn("Should SetIPv6() here to", s)
@ -162,6 +162,7 @@ func (ds *digStatus) SetIPv6(s string) {
me.DnsAAAA.Set(s)
// me.digStatus.set(ds.httpGoWitCom, addr)
}
*/
func (ds *digStatus) set(a any, s string) {
if ! ds.Ready() {return}
@ -301,7 +302,7 @@ func (ds *digStatus) checkLookupDoH(hostname string) bool {
s = append(s, addr)
status = true
}
me.digStatus.SetIPv6(strings.Join(s, "\n"))
// me.digStatus.SetIPv6(strings.Join(s, "\n"))
return status
}

46
dns.go
View File

@ -40,42 +40,16 @@ func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
}
}
/*
func (h *Host) checkDNS() {
var ip4 bool = false
var ip6 bool = false
for s, t := range h.ipmap {
i := t.iface
ipt := "IPv4"
if (t.ipv6) {
ipt = "IPv6"
}
if (! t.IsReal()) {
log.Println(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
continue
}
log.Println(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) {
ip6 = true
} else {
ip4 = true
func lookupNSprovider(domain string) string {
for s, d := range me.nsmap {
log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
if (domain == d) {
// figure out the provider (google, cloudflare, etc)
return s + " blah"
}
}
if (ip4 == true) {
log.Println(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
} else {
log.Println(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
}
if (ip6 == true) {
log.Println(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
} else {
log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
}
return "blah"
}
*/
// nsLookup performs an NS lookup on the given domain name.
func lookupNS(domain string) {
@ -127,9 +101,15 @@ func setProvider(hostname string) {
if len(parts) >= 2 {
provider = parts[len(parts)-2]
}
if me.APIprovider != provider {
log.Log(CHANGE, "setProvider() changed to =", provider)
}
me.APIprovider = provider
/*
if (me.DnsAPI.S != provider) {
me.changed = true
log.Log(CHANGE, "setProvider() changed to =", provider)
me.DnsAPI.SetText(provider)
}
*/
}

View File

@ -20,25 +20,88 @@ type errorBox struct {
l *gui.Node
b *gui.Node
fixes map[string]*anError
something *gadgets.OneLiner
}
func NewErrorBox(p *gui.Node, name string) *errorBox {
type anError struct {
kind string // what kind of error is it?
aaaa string
status string
kindLabel *gui.Node
ipLabel *gui.Node
statusLabel *gui.Node
button *gui.Node
}
func NewErrorBox(p *gui.Node, name string, ip string) *errorBox {
var eb *errorBox
eb = new(errorBox)
eb.parent = p
// eb.group = p.NewGroup("eg")
// eb.grid = eb.group.NewGrid("labels", 2, 1)
eb.group = p.NewGroup(name)
eb.grid = eb.group.NewGrid("stuff", 4, 1)
eb.l = p.NewLabel("click to fix")
eb.b = p.NewButton("fix", func() {
log.Log(WARN, "should try to fix here")
})
eb.something = gadgets.NewOneLiner(eb.grid, "something")
eb.grid.NewLabel("Type")
eb.grid.NewLabel("IP")
eb.grid.NewLabel("Status")
eb.grid.NewLabel("")
eb.fixes = make(map[string]*anError)
return eb
}
func (eb *errorBox) add(kind string, ip string) bool {
tmp := kind + " " + ip
if eb.fixes[tmp] != nil {
log.Log(WARN, "Error is already here", kind, ip)
return false
}
anErr := new(anError)
anErr.kind = kind
anErr.aaaa = ip
anErr.kindLabel = eb.grid.NewLabel(kind)
anErr.ipLabel = eb.grid.NewLabel(ip)
anErr.statusLabel = eb.grid.NewLabel("")
anErr.button = eb.grid.NewButton(kind, func() {
log.Log(WARN, "got", kind, "here. IP =", ip)
eb.fix(tmp)
})
eb.fixes[tmp] = anErr
return false
}
func (eb *errorBox) fix(key string) bool {
if eb.fixes[key] == nil {
log.Log(WARN, "Unknown error. could not find key =", key)
log.Log(WARN, "TODO: probably remove this error. key =", key)
return true
}
myErr := eb.fixes[key]
log.Log(WARN, "should try to fix", myErr.kind, "here. IP =", myErr.aaaa)
if myErr.kind == "DELETE" {
if deleteFromDNS(myErr.aaaa) {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
} else {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
}
return true
}
if myErr.kind == "CREATE" {
if addToDNS(myErr.aaaa) {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
} else {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
}
return true
}
return false
}
func (eb *errorBox) update() bool {
return false
}

58
fix.go
View File

@ -8,7 +8,21 @@ import (
)
func fix() bool {
log.Log(CHANGE, "")
// make and toggle the fixWindow display
if me.fixWindow == nil {
me.fixWindow = smartwindow.New()
me.fixWindow.SetParent(me.myGui)
me.fixWindow.Title("fix window")
me.fixWindow.SetDraw(drawFixWindow)
me.fixWindow.Vertical()
me.fixWindow.Make()
me.fixWindow.Draw()
me.fixWindow.Hide()
// me.fixWindow.Draw2()
return false
}
me.fixWindow.Toggle()
if ! me.statusDNS.Ready() {
log.Log(CHANGE, "The IPv6 Control Panel is not Ready() yet")
return false
@ -65,7 +79,9 @@ func fixIPv6dns() bool {
// remove old DNS entries first
for aaaa, _ := range dnsAAAA {
if osAAAA[aaaa] == "dns" {
if osAAAA[aaaa] == "os" {
log.Log(INFO, "DNS AAAA is in OS", aaaa)
} else {
broken = true
log.Log(INFO, "DNS AAAA is not in OS", aaaa)
addToFixWindow("DELETE", aaaa)
@ -76,8 +92,6 @@ func fixIPv6dns() bool {
log.Log(INFO, "Delete AAAA", aaaa, "Failed")
}
*/
} else {
log.Log(INFO, "DNS AAAA is in OS", aaaa)
}
}
@ -104,16 +118,25 @@ func fixIPv6dns() bool {
}
func deleteFromDNS(aaaa string) bool {
log.Log(CHANGE, "deleteFromDNS", aaaa)
log.Log(CHANGE, "Delete this from DNS !!!!", aaaa)
api := me.statusDNS.API()
log.Log(CHANGE, "your API provider is =", api)
if api == "cloudflare" {
log.Log(CHANGE, "Let's try a DELETE via the Cloudflare API")
hostname := me.statusOS.GetHostname()
b, response := cloudflare.Delete("wit.com", hostname, aaaa)
log.Log(CHANGE, "response was:", response)
return b
}
return false
}
func addToDNS(aaaa string) bool {
log.Log(CHANGE, "TODO: Add this to DNS !!!!", aaaa)
log.Log(CHANGE, "Add this to DNS !!!!", aaaa)
api := me.statusDNS.API()
log.Log(CHANGE, "what is your API provider?", api)
log.Log(CHANGE, "your API provider is =", api)
if api == "cloudflare" {
log.Log(CHANGE, "Let's try an ADD via the Cloudflare API")
log.Log(CHANGE, "Let's try a CREATE via the Cloudflare API")
hostname := me.statusOS.GetHostname()
return cloudflare.Create("wit.com", hostname, aaaa)
}
@ -127,17 +150,24 @@ func exists(m map[string]bool, s string) bool {
return false
}
var myErrorBox *errorBox
func addToFixWindow(t string, ip string) {
log.Log(INFO, "addToFixWindow() START")
if me.fixWindow == nil {
me.fixWindow = smartwindow.New()
me.fixWindow.SetParent(me.myGui)
me.fixWindow.InitWindow()
me.fixWindow.Title("fix window")
me.fixWindow.SetDraw(drawFixWindow)
me.fixWindow.Make()
log.Log(WARN, "addToFixWindow() fixWindow == nil. Can't add the error", t, ip)
return
}
if myErrorBox == nil {
box := me.fixWindow.Box()
myErrorBox = NewErrorBox(box, t, ip)
}
myErrorBox.add(t, ip)
log.Log(INFO, "addToFixWindow() END")
}
func drawFixWindow(sw *smartwindow.SmartWindow) {
log.Log(WARN, "drawFixWindow() START")
box := sw.Box()
box.NewLabel("test")
}

233
gui.go
View File

@ -4,8 +4,6 @@ package main
import (
"time"
"os"
"strings"
"sort"
"go.wit.com/log"
@ -13,7 +11,8 @@ import (
"go.wit.com/gui/gadgets"
"go.wit.com/gui/cloudflare"
"go.wit.com/gui/debugger"
// "go.wit.com/control-panels/dns/linuxstatus"
"go.wit.com/gui/gadgets/logsettings"
"go.wit.com/control-panels/dns/smartwindow"
)
// This setups up the dns control panel window
@ -45,57 +44,37 @@ func debugTab(title string) {
})
g2 = me.debug.Box().NewGroup("debugging options")
gridP := g2.NewGrid("nuts", 2, 1)
// makes a slider widget
me.ttl = gadgets.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
me.ttl = gadgets.NewDurationSlider(gridP, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
me.ttl.Set(300 * time.Millisecond)
// makes a slider widget
me.dnsTtl = gadgets.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
me.dnsTtl = gadgets.NewDurationSlider(gridP, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
me.dnsTtl.Set(60 * time.Second)
gridP.NewLabel("dns resolution")
me.DnsSpeed = gridP.NewLabel("unknown")
gridP.NewLabel("dns resolution speed")
me.DnsSpeedActual = gridP.NewLabel("unknown")
gridP.NewLabel("Test speed")
newGrid := gridP.NewGrid("nuts", 2, 1).Pad()
g2.Margin()
g2.Pad()
newGrid.NewLabel("ping.wit.com =")
newGrid.NewLabel("unknown")
newGrid.NewLabel("ping6.wit.com =")
newGrid.NewLabel("unknown")
me.debug.Hide()
}
// doesn't actually do any network traffic
// it just updates the GUI
func displayDNS() string {
var aaaa []string
aaaa = append(aaaa, "blah", "more")
// h := me.hostname
var all string
var broken string = "unknown"
for _, s := range aaaa {
log.Log(STATUS, "host", "fixme", "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
all += s + "\n"
if ( me.ipmap[s] == nil) {
log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", "fixme", "DNS AAAA =", s)
broken = "wrong AAAA entry"
} else {
if (broken == "unknown") {
broken = "needs update"
}
}
}
var a []string
a = append(a, "fixme")
sort.Strings(a)
all = strings.Join(a, "\n")
if (all == "") {
log.Log(NOW, "THERE IS NOT a real A DNS ENTRY")
all = "CNAME ipv6.wit.com"
}
if (me.DnsA.S != all) {
log.Log(NOW, "DnsA.SetText() to:", all)
me.DnsA.SetText(all)
}
return broken
}
func myDefaultExit(n *gui.Node) {
log.Println("You can Do exit() things here")
os.Exit(0)
@ -105,37 +84,27 @@ func mainWindow(title string) {
me.window = gadgets.NewBasicWindow(me.myGui, title)
gr := me.window.Box().NewGroup("dns update")
grid := gr.NewGrid("gridnuts", 2, 2)
grid.SetNext(1,1)
me.hostname = gadgets.NewOneLiner(grid, "hostname =").Set("unknown")
me.DnsAAAA = gadgets.NewOneLiner(grid, "DNS AAAA =").Set("unknown")
grid.NewLabel("DNS A =")
me.DnsA = grid.NewLabel("?")
// This is where you figure out what to do next to fix the problems
me.fixButton = gr.NewButton("fix", func () {
me.fixButton = gr.NewButton("Check Errors", func () {
if ! fix() {
log.Log(CHANGE, "boo. IPv6 isn't working yet")
return
}
log.Log(CHANGE, "IPv6 WORKED")
// update everything here visually for the user
hostname := me.statusOS.GetHostname()
me.hostname.Set(hostname)
// hostname := me.statusOS.GetHostname()
// me.hostname.Set(hostname)
me.hostnameStatus.Set("WORKING")
me.DnsStatus.Set("WORKING")
me.fixButton.SetText("No Errors!")
me.fixButton.Disable()
})
grid.Margin()
grid.Pad()
statusGrid(me.window.Box())
gr = me.window.Box().NewGroup("debugging")
gr = me.window.Box().NewGroup("")
/*
me.statusDNSbutton = gr.NewButton("hostname status", func () {
if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle()
@ -147,57 +116,86 @@ func mainWindow(title string) {
if ! me.digStatus.Ready() {return}
me.digStatus.window.Toggle()
})
gr.NewButton("cloudflare wit.com", func () {
if me.witcom != nil {
me.witcom.Toggle()
}
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
})
*/
gr.NewButton("Debug", func () {
me.debug.Toggle()
})
var myLS *logsettings.LogSettings
gr.NewButton("Logging Settings", func () {
if myLS == nil {
// initialize the log settings window (does not display it)
myLS = logsettings.New(me.myGui)
return
}
myLS.Toggle()
})
gr.NewButton("Show Errors", func () {
if me.fixWindow == nil {
me.fixWindow = smartwindow.New()
me.fixWindow.SetParent(me.myGui)
me.fixWindow.Title("fix window")
me.fixWindow.SetDraw(drawFixWindow)
me.fixWindow.Vertical()
me.fixWindow.Make()
me.fixWindow.Draw()
me.fixWindow.Hide()
return
}
me.fixWindow.Toggle()
})
}
func statusGrid(n *gui.Node) {
problems := n.NewGroup("status")
problems.Margin()
problems.Pad()
gridP := problems.NewGrid("nuts", 2, 2)
gridP := problems.NewGrid("nuts", 3, 1)
gridP.Margin()
gridP.Pad()
gridP.NewLabel("hostname =")
me.hostnameStatus = gridP.NewLabel("invalid")
gridP.NewButton("Linux Status", func () {
me.statusOS.Toggle()
})
gridP.NewLabel("DNS Status =")
me.DnsStatus = gridP.NewLabel("unknown")
me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
me.statusIPv6 = gadgets.NewOneLiner(gridP, "DNS Lookup")
me.statusIPv6.Set("known")
gridP.NewButton("resolver status", func () {
if ! me.digStatus.Ready() {return}
me.digStatus.window.Toggle()
})
gridP.NewLabel("dns resolution")
me.DnsSpeed = gridP.NewLabel("unknown")
gridP.NewLabel("DNS Status")
me.DnsStatus = gridP.NewLabel("unknown")
me.statusDNSbutton = gridP.NewButton("hostname status", func () {
if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle()
})
gridP.NewLabel("dns resolution speed")
me.DnsSpeedActual = gridP.NewLabel("unknown")
gridP.NewLabel("DNS API")
me.DnsAPIstatus = gridP.NewLabel("unknown")
var apiButton *gui.Node
apiButton = gridP.NewButton("unknown wit.com", func () {
log.Log(CHANGE, "WHAT API ARE YOU USING?")
provider := me.statusDNS.GetDNSapi()
apiButton.SetText(provider + " wit.com")
if provider == "cloudflare" {
me.DnsAPIstatus.Set("WORKING")
return
gridP.NewLabel("dns API provider =")
me.DnsAPI = gridP.NewLabel("unknown")
if me.witcom != nil {
me.witcom.Toggle()
}
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
}
})
gridP.Margin()
gridP.Pad()
n.NewGroup("NOTES")
// TODO: these are notes for me things to figure out
ng := n.NewGroup("TODO:")
gridP = ng.NewGrid("nut2", 2, 2)
gridP.NewLabel("ping.wit.com =")
gridP.NewLabel("unknown")
gridP.NewLabel("ping6.wit.com =")
gridP.NewLabel("unknown")
problems.Margin()
problems.Pad()
gridP.Margin()
gridP.Pad()
}
// run everything because something has changed
@ -205,67 +203,14 @@ func updateDNS() {
me.digStatus.Update()
me.statusDNS.Update()
// log.Println("digAAAA()")
if me.statusOS.ValidHostname() {
var aaaa []string
h := me.statusOS.GetHostname()
aaaa = digAAAA(h)
log.Log(INFO, "digAAAA() for", h, "=", aaaa)
// log.Println(SPEW, me)
if (aaaa == nil) {
log.Warn("There are no DNS AAAA records for hostname: ", h)
me.DnsAAAA.Set("(none)")
if (cloudflare.CFdialog.TypeNode != nil) {
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
}
if (cloudflare.CFdialog.NameNode != nil) {
cloudflare.CFdialog.NameNode.SetText(h)
}
/*
d := deleteAAA()
if (d != "") {
if (cloudflare.CFdialog.ValueNode != nil) {
cloudflare.CFdialog.ValueNode.SetText(d)
}
}
*/
// m := missingAAAA()
// if (m != "") {
// if (cloudflare.CFdialog.ValueNode != nil) {
// cloudflare.CFdialog.ValueNode.SetText(m)
// }
// /*
// rr := &cloudflare.RRT{
// Type: "AAAA",
// Name: me.hostname,
// Ttl: "Auto",
// Proxied: false,
// Content: m,
// }
// cloudflare.Update(rr)
// */
// }
}
}
status := displayDNS() // update the GUI based on dig results
me.DnsStatus.SetText(status)
if me.digStatus.Ready() {
if me.digStatus.IPv6() {
me.statusIPv6.Set("IPv6 WORKING")
me.statusIPv6.Set("WORKING")
} else {
me.statusIPv6.Set("Need VPN")
}
}
// me.fix.Enable()
// lookup the NS records for your domain
// if your host is test.wit.com, find the NS resource records for wit.com
lookupNS(me.statusOS.GetDomainName())

View File

@ -323,7 +323,9 @@ func (hs *hostnameStatus) updateStatus() {
hs.status.Set("BROKEN")
}
hs.dnsAPI.Set(me.DnsAPI.S)
// lookup the DNS provider
// hs.dnsAPI.Set(me.DnsAPI.S)
lookupNSprovider("wit.com")
}
func (hs *hostnameStatus) Show() {
@ -341,3 +343,7 @@ func (hs *hostnameStatus) Hide() {
}
hs.hidden = true
}
func (hs *hostnameStatus) GetDNSapi() string {
return me.APIprovider
}

View File

@ -33,7 +33,7 @@ func (ls *LinuxStatus) GetHostname() string {
func (ls *LinuxStatus) ValidHostname() bool {
if ! me.Ready() {return false}
if me.hostnameStatus.Get() == "VALID" {
if me.hostnameStatus.Get() == "WORKING" {
return true
}
return false
@ -104,9 +104,9 @@ func lookupHostname() {
me.hostnameStatus.Set("BROKEN")
}
} else {
if (me.hostnameStatus.Get() != "VALID") {
if (me.hostnameStatus.Get() != "WORKING") {
log.Log(CHANGE, "hostname", hostname, "is valid")
me.hostnameStatus.Set("VALID")
me.hostnameStatus.Set("WORKING")
me.changed = true
}
}

View File

@ -18,11 +18,11 @@ func (ls *LinuxStatus) Update() {
duration := timeFunction(func () {
linuxLoop()
})
ls.SetSpeed(duration)
ls.setSpeed(duration)
log.Log(INFO, "Update() END")
}
func (ls *LinuxStatus) SetSpeed(duration time.Duration) {
func (ls *LinuxStatus) setSpeed(duration time.Duration) {
s := fmt.Sprint(duration)
if ls.speedActual == nil {
log.Log(WARN, "can't actually warn")

View File

@ -157,9 +157,17 @@ func dnsTTL() {
}
// run update on the LinuxStatus() window
// also update a few things on the main window
func linuxLoop() {
me.statusOS.Update()
if me.statusOS.ValidHostname() {
if me.hostnameStatus.GetText() != "WORKING" {
me.hostnameStatus.Set("WORKING")
me.changed = true
}
}
if (me.statusOS.Changed()) {
stamp := time.Now().Format("2006/01/02 15:04:05")
log.Log(CHANGE, "Network things changed on", stamp)

View File

@ -8,17 +8,15 @@ import (
)
func (sw *SmartWindow) Ready() bool {
log.Log(WARN, "Ready() maybe not ready? sw =", sw)
if sw == nil {return false}
log.Log(INFO, "Ready() START")
if sw == nil {return false}
if sw.window == nil {return false}
log.Log(INFO, "Ready() END sw.ready =", sw.ready)
return sw.ready
}
func (sw *SmartWindow) Initialized() bool {
log.Log(WARN, "checking Initialized()")
log.Log(INFO, "checking Initialized()")
if sw == nil {return false}
if sw == nil {return false}
if sw.parent == nil {return false}
return true
}

View File

@ -2,8 +2,6 @@ package smartwindow
import (
"go.wit.com/log"
"go.wit.com/gui/gadgets"
)
func New() *SmartWindow {
@ -25,8 +23,4 @@ func (sw *SmartWindow) InitWindow() {
sw.ready = true
return
}
log.Log(WARN, "Creating the Window")
sw.window = gadgets.NewBasicWindow(sw.parent, sw.title)
sw.ready = true
}

View File

@ -55,5 +55,24 @@ func (sw *SmartWindow) Toggle() {
func (sw *SmartWindow) Box() *gui.Node {
if ! sw.Ready() {return nil}
return sw.window.Box()
return sw.box
}
func (sw *SmartWindow) Draw() {
if ! sw.Ready() {return}
log.Log(WARN, "Draw() window ready")
sw.window.Draw()
if sw.vertical {
sw.box = sw.window.NewBox("bw vbox", false)
log.Log(WARN, "BasicWindow.Custom() made vbox")
} else {
sw.box = sw.window.NewBox("bw hbox", true)
log.Log(WARN, "BasicWindow.Custom() made hbox")
}
if (sw.populate != nil) {
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
sw.populate(sw)
}
}

View File

@ -36,49 +36,37 @@ func (sw *SmartWindow) SetParent(p *gui.Node) {
}
func (sw *SmartWindow) SetDraw(f func(*SmartWindow)) {
if ! sw.Initialized() {return}
if sw.Ready() {return}
log.Log(WARN, "SetDraw() START")
if ! sw.Initialized() {
log.Log(WARN, "SetDraw() Failed. sw.Initialized == false")
return
}
if sw.Ready() {
log.Log(WARN, "SetDraw() Failed. sw.Ready() == true")
return
}
sw.populate = f
log.Log(WARN, "SetDraw() END sw.populate is set")
}
func (sw *SmartWindow) Make() {
if ! sw.Initialized() {return}
if sw.Ready() {return}
log.Log(WARN, "Make() START")
log.Log(WARN, "Make() window ready =", sw.ready)
sw.window.Make()
if (sw.populate != nil) {
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
sw.populate(sw)
sw.window = sw.parent.RawWindow(sw.title)
sw.window.Custom = func() {
log.Warn("BasicWindow.Custom() closed. TODO: handle this", sw.title)
}
log.Log(WARN, "Make() END sw.window = RawWindow() (not sent to toolkits)")
sw.ready = true
}
func (sw *SmartWindow) Draw() {
if ! sw.Initialized() {return}
if sw.Ready() {return}
log.Log(WARN, "Draw() window ready =", sw.ready)
sw.window.Draw()
if (sw.populate != nil) {
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
sw.populate(sw)
}
sw.ready = true
}
func (sw *SmartWindow) Vertical() {
if ! sw.Initialized() {return}
if sw.Ready() {return}
log.Log(WARN, "Draw() window ready =", sw.ready)
sw.window.Draw()
if (sw.populate != nil) {
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
sw.populate(sw)
}
sw.ready = true
log.Log(WARN, "Vertical() setting vertical = true")
sw.vertical = true
}

View File

@ -2,19 +2,19 @@ package smartwindow
import (
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
type SmartWindow struct {
ready bool // track if the window is ready
hidden bool // track if the window is hidden from the toolkits
changed bool // track if something changed in the window
vertical bool
title string // what the user sees as the name
name string // the programatic name aka: "CALANDAR"
parent *gui.Node // where to place the window if you try to draw it
window *gadgets.BasicWindow // the underlying BasicWindow
window *gui.Node // the underlying window
box *gui.Node // the box inside the window // get this from BasicWindow() ?
populate func(*SmartWindow) // the function to generate the widgets

View File

@ -26,8 +26,10 @@ type Host struct {
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
digStatus *digStatus // window of the results of DNS lookups
// WHEN THESE ARE ALL "WORKING", then everything is good
hostnameStatus *gui.Node // a summary for the user of where things are
hostname *gadgets.OneLiner // the hostname grabbed from gadget.linuxStatus
DnsAPIstatus *gui.Node // does your DNS API work?
APIprovider string
artificialSleep float64 `default:"0.7"` // artificial sleep on startup
artificialS string `default:"abc"` // artificial sleep on startup
@ -49,9 +51,6 @@ type Host struct {
ipv6s map[string]dns.RR
// DNS stuff
DnsAPI *gui.Node // what DNS API to use?
DnsAAAA *gadgets.OneLiner // the actual DNS AAAA results
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
DnsStatus *gui.Node // the current state of DNS
DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc
DnsSpeedActual *gui.Node // the last actual duration