diff options
| -rw-r--r-- | addText.go | 13 | ||||
| -rw-r--r-- | init.go | 35 | ||||
| -rw-r--r-- | plugin.go | 5 | ||||
| -rw-r--r-- | watchdog.go | 6 |
4 files changed, 34 insertions, 25 deletions
@@ -18,19 +18,6 @@ func (n *Node) addText(newS string) { } n.strings[newS] = highest + 1 // TODO: use the int's for the order n.newString = newS - /* - // time.Sleep(time.Duration(1000 * time.Nanosecond)) // doesn't work - // maybe this stupid chipset is defective. TODO: try on different hardware - // tried with go 1.21.4 debian sid - mylock.Lock() - n.mu.Lock() - // time.Sleep(time.Duration(10 * time.Microsecond)) // doesn't work - time.Sleep(time.Duration(100 * time.Microsecond)) // does work - n.strings = append(n.strings, newS) - n.mu.Unlock() - mylock.Unlock() - log.Log(INFO, "addText() has strings:", n.strings) - */ // inform the toolkits sendAction(n, widget.AddText) @@ -15,6 +15,11 @@ import ( // const Yaxis = 1 // stack things vertically func initNew() { + defer func() { + if r := recover(); r != nil { + crash(r, "watchCallback()") + } + }() log.Log(INFO, "init() has been run") me.counter = 0 @@ -75,7 +80,7 @@ func getGuiVersion() (string, error) { return "", errors.New("debug.ReadBuildInfo() not ok") } if tmp == nil { - return "", errors.New("compiled without go module support") + return "", errors.New("compiled without GO module support") } // log.Println("mod.Path = ", tmp.Path) // log.Println("mod.Main.Path = ", tmp.Main.Path) @@ -173,7 +178,19 @@ func toolkitPanic(pname string) { me.rootNode.LoadToolkit("nocui") } +func crash(r any, what string) { + log.Warn("PANIC ecovered in ", r, what) + UnloadToolkits() + log.Warn("PANIC ecovered in before n.Custom()", r, what) + os.Exit(-1) +} + func watchCallback() { + defer func() { + if r := recover(); r != nil { + crash(r, "watchCallback()") + } + }() log.Log(INFO, "guiChan() START") for { log.Log(CHANGE, "guiChan() select restarted") @@ -237,6 +254,11 @@ func watchCallback() { // that it doesn't matter what happens outside of here // TODO: implement throttling someday func (n *Node) gotUserEvent(a widget.Action) { + defer func() { + if r := recover(); r != nil { + crash(r, "watchCallback()") + } + }() log.Log(CHANGE, "gotUserEvent() received event node =", n.id, n.progname, a.Value) if !n.IsEnabled() { @@ -278,7 +300,16 @@ func (n *Node) gotUserEvent(a widget.Action) { log.Log(CHANGE, "a Custom() function was not set for this widget") return } - go n.Custom() + go something(n) +} + +func something(n *Node) { + defer func() { + if r := recover(); r != nil { + crash(r, "watchCallback()") + } + }() + n.Custom() } // There should only be one of these per application @@ -160,11 +160,8 @@ func searchPaths(name string) *aplug { } // check for custom toolkit builds. This looks: - // with 'go build': ~/go/src/go.wit.com/toolkits/gocui/gocui.go - // with 'make install': ~/go/lib/go-gui/gocui.go - // // TODO: use forge to find the "go.work" dir - // TODO: fix 'go install' to support building plugins + // TODO: fix GO as language to support building plugins homeDir, err := os.UserHomeDir() if err != nil { log.Error(err, "os.UserHomeDir() error", err) diff --git a/watchdog.go b/watchdog.go index 2bd745a..cba0097 100644 --- a/watchdog.go +++ b/watchdog.go @@ -27,12 +27,6 @@ func myTicker(t time.Duration, name string, f func()) { ticker := time.NewTicker(t) defer ticker.Stop() done := make(chan bool) - /* - go func() { - time.Sleep(10 * time.Second) - done <- true - }() - */ for { select { case <-done: |
