summaryrefslogtreecommitdiff
path: root/plugin.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin.go')
-rw-r--r--plugin.go60
1 files changed, 31 insertions, 29 deletions
diff --git a/plugin.go b/plugin.go
index d1b4b2c..f957dba 100644
--- a/plugin.go
+++ b/plugin.go
@@ -6,21 +6,22 @@ package gui
// It's a pleasure to be here with all of you
import (
- "os"
"embed"
+ "os"
"plugin"
+ "go.wit.com/lib/widget"
"go.wit.com/log"
- "go.wit.com/gui/widget"
)
var err error
+
type Symbol any
type aplug struct {
- name string
+ name string
filename string
- plug *plugin.Plugin
+ plug *plugin.Plugin
// this tells the toolkit plugin how to send events
// back here
@@ -33,7 +34,7 @@ type aplug struct {
//
Callback func(chan widget.Action)
- // This is how actions are sent to the toolkit.
+ // This is how actions are sent to the toolkit.
// For example:
// If a program is using GTK, when a program tries to make a new button
// "Open GIMP", then it would pass an action via this channel into the toolkit
@@ -42,7 +43,7 @@ type aplug struct {
// each toolkit has it's own goroutine and each one is sent this
// add button request
//
- pluginChan chan widget.Action
+ pluginChan chan widget.Action
PluginChannel func() chan widget.Action
}
@@ -55,7 +56,7 @@ func initPlugin(name string) *aplug {
for _, aplug := range allPlugins {
log.Log(PLUG, "initPlugin() already loaded toolkit plugin =", aplug.name)
- if (aplug.name == name) {
+ if aplug.name == name {
log.Warn("initPlugin() SKIPPING", name, "as you can't load it twice")
return nil
}
@@ -64,7 +65,7 @@ func initPlugin(name string) *aplug {
return searchPaths(name)
}
-// newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
+// newPlug.PluginChannel = getPluginChannel(newPlug, "PluginChannel")
func getPluginChannel(p *aplug, funcName string) func() chan widget.Action {
var newfunc func() chan widget.Action
var ok bool
@@ -104,12 +105,13 @@ func sendCallback(p *aplug, funcName string) func(chan widget.Action) {
}
/*
- TODO: clean this up. use command args?
- TODO: use LD_LIBRARY_PATH ?
- This searches in the following order for the plugin .so files:
- ./toolkit/
- ~/go/src/go.wit.com/gui/toolkit/
- /usr/lib/go-gui/
+TODO: clean this up. use command args?
+TODO: use LD_LIBRARY_PATH ?
+This searches in the following order for the plugin .so files:
+
+ ./toolkit/
+ ~/go/src/go.wit.com/toolkits/
+ /usr/lib/go-gui/
*/
func searchPaths(name string) *aplug {
var filename string
@@ -119,14 +121,14 @@ func searchPaths(name string) *aplug {
// first try to load the embedded plugin file
filename = "resources/" + name + ".so"
pfile, err = me.resFS.ReadFile(filename)
- if (err == nil) {
+ if err == nil {
filename = "/tmp/" + name + ".so"
log.Error(err, "write out file here", name, filename, len(pfile))
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
f.Write(pfile)
f.Close()
p := initToolkit(name, filename)
- if (p != nil) {
+ if p != nil {
return p
}
} else {
@@ -134,9 +136,9 @@ func searchPaths(name string) *aplug {
}
// attempt to write out the file from the internal resource
- filename = "toolkits/" + name + ".so"
+ filename = "resources/" + name + ".so"
p := initToolkit(name, filename)
- if (p != nil) {
+ if p != nil {
return p
}
@@ -146,21 +148,21 @@ func searchPaths(name string) *aplug {
return nil
}
- filename = homeDir + "/go/src/go.wit.com/gui/toolkits/" + name + ".so"
+ filename = homeDir + "/go/src/go.wit.com/toolkits/" + name + ".so"
p = initToolkit(name, filename)
- if (p != nil) {
+ if p != nil {
return p
}
filename = "/usr/lib/go-gui/latest/" + name + ".so"
p = initToolkit(name, filename)
- if (p != nil) {
+ if p != nil {
return p
}
filename = "/usr/local/lib/gui/toolkits/" + name + ".so"
p = initToolkit(name, filename)
- if (p != nil) {
+ if p != nil {
return p
}
return nil
@@ -203,7 +205,7 @@ func initToolkit(name string, filename string) *aplug {
// set the communication to the plugins
newPlug.pluginChan = newPlug.PluginChannel()
- if (newPlug.pluginChan == nil) {
+ if newPlug.pluginChan == nil {
log.Warn("initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename)
return nil
}
@@ -221,14 +223,14 @@ func (n *Node) InitEmbed(resFS embed.FS) *Node {
func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
for _, aplug := range allPlugins {
log.Info("LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name)
- if (aplug.name == name) {
+ if aplug.name == name {
log.Warn("LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
return n
}
}
- f, err := os.CreateTemp("", "sample." + name + ".so")
- if (err != nil) {
+ f, err := os.CreateTemp("", "sample."+name+".so")
+ if err != nil {
log.Error(err, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice")
return n
}
@@ -236,7 +238,7 @@ func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node {
f.Write(b)
p := initToolkit(name, f.Name())
- if (p == nil) {
+ if p == nil {
log.Warn("LoadToolkitEmbed() embedded go file failed", name)
}
return n
@@ -251,7 +253,7 @@ func (n *Node) ListToolkits() {
func (n *Node) LoadToolkit(name string) *Node {
log.Log(PLUG, "LoadToolkit() START for name =", name)
plug := initPlugin(name)
- if (plug == nil) {
+ if plug == nil {
return n
}
@@ -271,7 +273,7 @@ func (n *Node) CloseToolkit(name string) bool {
log.Log(PLUG, "CloseToolkit() for name =", name)
for _, plug := range allPlugins {
log.Log(PLUG, "CloseToolkit() found", plug.name)
- if (plug.name == name) {
+ if plug.name == name {
log.Log(PLUG, "CloseToolkit() sending close", name)
var a widget.Action
a.ActionType = widget.ToolkitClose