From 827a258a867a652ea2207877d3dc7541d1afca26 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 12 Feb 2025 17:00:44 -0600 Subject: [PATCH] initOnce() --- plugin.go | 19 +++++++++++++++++++ structs.go | 1 + 2 files changed, 20 insertions(+) diff --git a/plugin.go b/plugin.go index 61ae47f..426e500 100644 --- a/plugin.go +++ b/plugin.go @@ -9,6 +9,8 @@ package tree */ import ( + "time" + "go.wit.com/widget" ) @@ -36,6 +38,21 @@ func (n *Node) FindWidgetId(id int) *Node { 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 // // 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 } +// this is the function that receives things from the application func (me *TreeInfo) PluginChannel() chan widget.Action { + me.waitOK() return me.pluginChan } diff --git a/structs.go b/structs.go index c4792b7..6b7516d 100644 --- a/structs.go +++ b/structs.go @@ -17,6 +17,7 @@ import ( var treeRoot *Node type TreeInfo struct { + ok bool // indicates the plugin actually initialized PluginName string // used to identify the plugin config *ToolkitConfigs // protobuf of plugin settings callback chan widget.Action // mouse clicks or keyboard events back to the program