summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-07 21:54:57 -0500
committerJeff Carr <[email protected]>2023-04-07 21:54:57 -0500
commit59df0c2e206a6d9a77041b1ed14c9069d3f779ab (patch)
tree55e1d39f10fe8382989e39ff5817fa8ce1b80dbe
parenta975a73ac133d1ba76cb5babd950bd19d36e8443 (diff)
more progres on channels
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--README-goreadme.md4
-rw-r--r--main.go13
-rw-r--r--plugin.go41
3 files changed, 51 insertions, 7 deletions
diff --git a/README-goreadme.md b/README-goreadme.md
index e83340f..c6e0d00 100644
--- a/README-goreadme.md
+++ b/README-goreadme.md
@@ -134,7 +134,7 @@ Creates a window helpful for debugging this package
TODO: add logic to just load the 1st 'most common' gui toolkit
and allow the 'go-arg' command line args to override the defaults
-### func [LoadToolkit](/plugin.go#L66)
+### func [LoadToolkit](/plugin.go#L68)
`func LoadToolkit(name string) *aplug`
@@ -162,7 +162,7 @@ This should not pass a function
`func ShowDebugValues()`
-### func [StandardExit](/main.go#L264)
+### func [StandardExit](/main.go#L273)
`func StandardExit()`
diff --git a/main.go b/main.go
index 65c184a..db9664d 100644
--- a/main.go
+++ b/main.go
@@ -218,12 +218,21 @@ func Main(f func()) {
}
aplug.MainOk = true
if (aplug.Callback == nil) {
- // TODO: don't load the module if this failed
+ // TODO: don't load the module if this failed ?
// if Callback() isn't set in the plugin, no information can be sent to it!
- log(debugError, "SERIOUS ERROR: Callback() == nil. nothing will work for plugin", aplug.name)
+ log(debugError, "SERIOUS ERROR: plugin Callback() == nil. nothing will work for toolkit", aplug.name)
} else {
aplug.Callback(Config.guiChan)
}
+
+ if (aplug.PluginChannel == nil) {
+ // TODO: don't load the module if this failed ?
+ // if Callback() isn't set in the plugin, no information can be sent to it!
+ log(debugError, "ERROR: plugin does not implement a send channel. toolkit =", aplug.name)
+ } else {
+ aplug.pluginChan = aplug.PluginChannel()
+ }
+
aplug.Main(f)
}
diff --git a/plugin.go b/plugin.go
index ada310d..1b3499d 100644
--- a/plugin.go
+++ b/plugin.go
@@ -48,6 +48,8 @@ type aplug struct {
// add button request
pluginChan chan toolkit.Action
+ PluginChannel func() chan toolkit.Action
+
// deprecate all this
// TODO: make Main() main() and never allow the user to call it
// run plugin.Main() when the plugin is loaded
@@ -104,7 +106,13 @@ func LoadToolkit(name string) *aplug {
// Sends a widget (button, checkbox, etc) and it's parent widget
newPlug.Action = loadFuncA(newPlug, "Action")
- newPlug.Callback = loadCallback(newPlug, "Callback")
+ // this tells the toolkit plugin how to send user events back to us
+ // for things like: the user clicked on the 'Check IPv6'
+ newPlug.Callback = sendCallback(newPlug, "Callback")
+
+ // this let's us know where to send requests to the toolkit
+ // for things like: add a new button called 'Check IPv6'
+ newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
allPlugins = append(allPlugins, newPlug)
@@ -136,7 +144,27 @@ func loadFuncE(p *aplug, funcName string) func() {
return newfunc
}
-func loadCallback(p *aplug, funcName string) func(chan toolkit.Action) {
+// newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
+func getPluginChannel(p *aplug, funcName string) func() chan toolkit.Action {
+ var newfunc func() chan toolkit.Action
+ var ok bool
+ var test plugin.Symbol
+
+ test, err = p.plug.Lookup(funcName)
+ if err != nil {
+ log(debugGui, "DID NOT FIND: name =", test, "err =", err)
+ return nil
+ }
+
+ newfunc, ok = test.(func() chan toolkit.Action)
+ if !ok {
+ log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
+ return nil
+ }
+ return newfunc
+}
+
+func sendCallback(p *aplug, funcName string) func(chan toolkit.Action) {
var newfunc func(chan toolkit.Action)
var ok bool
var test plugin.Symbol
@@ -307,7 +335,14 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
log(debugPlugin, "Failed Action() == nil for", aplug.name)
continue
}
- aplug.Action(a)
+ if (aplug.pluginChan == nil) {
+ aplug.Action(a)
+ } else {
+ log(debugNow, "Action() SEND pluginChan")
+ log(debugNow, "Action() SEND pluginChan")
+ log(debugNow, "Action() SEND pluginChan")
+ aplug.pluginChan <- *a
+ }
}
// increment where to put the next widget in a grid or table
if (where != nil) {