more progres on channels

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-07 21:54:57 -05:00
parent 5d032e68eb
commit b7ef4f6a2e
3 changed files with 51 additions and 7 deletions

View File

@ -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()`

13
main.go
View File

@ -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)
}

View File

@ -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) {