2025-02-02 13:03:44 -06:00
|
|
|
// Although most code from WIT.COM Inc is under the GPL
|
|
|
|
// This code is more generic because it must be able
|
|
|
|
// to be used in any GUI plugin
|
|
|
|
|
2024-01-18 00:05:54 -06:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
2025-02-08 06:35:38 -06:00
|
|
|
"fmt"
|
2024-02-09 10:26:42 -06:00
|
|
|
"os"
|
2024-02-09 09:30:50 -06:00
|
|
|
"runtime/debug"
|
2024-01-18 04:08:11 -06:00
|
|
|
"sync"
|
2024-01-18 00:05:54 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:08:11 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:05:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
var muAction sync.Mutex
|
|
|
|
|
|
|
|
func (me *TreeInfo) catchActionChannel() {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2025-02-02 13:03:44 -06:00
|
|
|
log.Log(TREEWARN, "YAHOOOO. Recovered in tree.catchActionChannel()", r)
|
|
|
|
log.Log(TREEWARN, "YAHOOOO. Recovered in tree.catchActionChannel() Plugin:", me.PluginName)
|
2024-01-19 12:08:21 -06:00
|
|
|
me.SendToolkitPanic()
|
2024-02-09 09:30:50 -06:00
|
|
|
debug.PrintStack()
|
2024-02-07 15:22:47 -06:00
|
|
|
me.ToolkitClose()
|
2024-02-09 10:26:42 -06:00
|
|
|
if me.PluginName == "nocui" {
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2024-01-18 00:05:54 -06:00
|
|
|
}
|
|
|
|
}()
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "catchActionChannel() START")
|
2024-01-18 00:05:54 -06:00
|
|
|
for {
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "catchActionChannel() for loop")
|
2024-01-18 04:08:11 -06:00
|
|
|
select {
|
2024-01-18 00:05:54 -06:00
|
|
|
case a := <-me.pluginChan:
|
2024-01-18 21:26:36 -06:00
|
|
|
log.Verbose("catchActionChannel() on ", a.WidgetId, a.WidgetType, a.ProgName)
|
2024-01-18 00:05:54 -06:00
|
|
|
muAction.Lock()
|
2025-02-13 22:28:46 -06:00
|
|
|
me.WaitOK()
|
2025-02-14 19:12:18 -06:00
|
|
|
// time.Sleep(10 * time.Millisecond)
|
2025-02-13 17:52:43 -06:00
|
|
|
me.doAction(a)
|
2024-01-18 00:05:54 -06:00
|
|
|
muAction.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *TreeInfo {
|
|
|
|
me := new(TreeInfo)
|
|
|
|
me.pluginChan = make(chan widget.Action, 1)
|
2025-02-08 06:35:38 -06:00
|
|
|
me.config = configLoad()
|
2024-01-18 00:05:54 -06:00
|
|
|
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "Init() start channel reciever")
|
2024-01-18 00:05:54 -06:00
|
|
|
go me.catchActionChannel()
|
2024-01-21 10:25:41 -06:00
|
|
|
log.Log(TREE, "Init() END")
|
2024-01-18 00:05:54 -06:00
|
|
|
return me
|
|
|
|
}
|
2025-02-08 06:35:38 -06:00
|
|
|
|
|
|
|
func (t *TreeInfo) ConfigFind(n string) (string, error) {
|
|
|
|
all := t.config.All() // get the list of repos
|
|
|
|
for all.Scan() {
|
|
|
|
r := all.Next()
|
|
|
|
if t.PluginName != r.Plugin {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if n == r.Name {
|
|
|
|
return r.Value, nil
|
|
|
|
}
|
|
|
|
log.Info("toolkit config", r.Plugin, r.Name, r.Value, n)
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("toolkit config %s not found", n)
|
|
|
|
}
|