initOnce()

This commit is contained in:
Jeff Carr 2025-02-12 17:00:44 -06:00
parent db0986fa06
commit 827a258a86
2 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,8 @@ package tree
*/ */
import ( import (
"time"
"go.wit.com/widget" "go.wit.com/widget"
) )
@ -36,6 +38,21 @@ func (n *Node) FindWidgetId(id int) *Node {
return nil return nil
} }
func (me *TreeInfo) InitOK() {
me.ok = true
}
// this hack is to wait for the application to send something
// before trying to do anything. todo: rethink this someday
func (me *TreeInfo) waitOK() {
for {
if me.ok {
return
}
time.Sleep(10 * time.Millisecond)
}
}
// Other goroutines must use this to access the GUI // Other goroutines must use this to access the GUI
// //
// You can not acess / process the GUI thread directly from // You can not acess / process the GUI thread directly from
@ -47,6 +64,8 @@ func (me *TreeInfo) Callback(guiCallback chan widget.Action) {
me.callback = guiCallback me.callback = guiCallback
} }
// this is the function that receives things from the application
func (me *TreeInfo) PluginChannel() chan widget.Action { func (me *TreeInfo) PluginChannel() chan widget.Action {
me.waitOK()
return me.pluginChan return me.pluginChan
} }

View File

@ -17,6 +17,7 @@ import (
var treeRoot *Node var treeRoot *Node
type TreeInfo struct { type TreeInfo struct {
ok bool // indicates the plugin actually initialized
PluginName string // used to identify the plugin PluginName string // used to identify the plugin
config *ToolkitConfigs // protobuf of plugin settings config *ToolkitConfigs // protobuf of plugin settings
callback chan widget.Action // mouse clicks or keyboard events back to the program callback chan widget.Action // mouse clicks or keyboard events back to the program