summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-09 09:29:55 -0600
committerJeff Carr <[email protected]>2024-02-09 09:29:55 -0600
commitc7ea23ddb6559030d0be98bff090bf919b0c4265 (patch)
tree8c2cbd57709c683914e0ffd639e86e07950529a6
parent8317fa28e2da1d22d7248874ebc794189faf23b5 (diff)
gocui panic() loads nocui correctlyv0.20.3v0.20.2
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--action.go6
-rw-r--r--main.go52
-rw-r--r--plugin.go5
3 files changed, 39 insertions, 24 deletions
diff --git a/action.go b/action.go
index a15fcb3..8b40983 100644
--- a/action.go
+++ b/action.go
@@ -160,7 +160,11 @@ func sendAction(n *Node, atype widget.ActionType) {
// sends the action/event to each toolkit via a golang plugin channel
func sendActionToPlugin(a *widget.Action) {
for _, aplug := range allPlugins {
- log.Log(PLUG, "send to toolkit =", aplug.name, "Action type=", a.ActionType, a.WidgetId)
+ log.Log(CHANGE, "send to toolkit =", aplug.name, "Action type=", a.ActionType, a.WidgetId)
+ if aplug.dead {
+ // log.Log(WARN, "skiping dead toolkit =", aplug.name, "Action type=", a.ActionType, a.WidgetId)
+ return
+ }
if aplug.pluginChan == nil {
log.Log(PLUG, "Action() retrieving the aplug.PluginChannel()", aplug.name)
aplug.pluginChan = aplug.PluginChannel()
diff --git a/main.go b/main.go
index 3b8dfc5..df716e3 100644
--- a/main.go
+++ b/main.go
@@ -65,12 +65,35 @@ func pluginCounter(a *widget.Action) {
found = true
}
}
- if ! found {
+ if !found {
// TODO: fix this by making seperate channels for each plugin?
log.Log(WARN, "ListToolkits() got event from unidentified plugin")
}
}
+func toolkitPanic(pname string) {
+ log.Log(WARN, "toolkitPanic() in", pname)
+ log.Log(WARN, "toolkitPanic() unload toolkit plugin here", pname)
+ me.rootNode.ListToolkits()
+ for _, aplug := range allPlugins {
+ if aplug.name == pname {
+ log.Log(WARN, "toolkitPanic() FOUND PLUGIN =", aplug.name)
+ log.Log(WARN, "toolkitPanic() unload here aplug.dead =", aplug.dead)
+ log.Log(WARN, "toolkitPanic() TODO: stop talking to plugin:", pname)
+ aplug.dead = true
+ log.Log(WARN, "toolkitPanic() unload here aplug.dead =", aplug.dead)
+ // me.rootNode.CloseToolkit(aplug.name)
+ // panic("panic trapped!")
+ // log.Sleep(.5)
+ // me.rootNode.LoadToolkit("gocui")
+ }
+ }
+ // log.UnsetTmp()
+ // StandardExit()
+ log.Log(WARN, "toolkitPanic() attempt to load nocui")
+ me.rootNode.LoadToolkit("nocui")
+}
+
func watchCallback() {
log.Log(INFO, "guiChan() START")
for {
@@ -79,6 +102,11 @@ func watchCallback() {
case a := <-me.guiChan:
pluginCounter(&a)
+ if a.ActionType == widget.ToolkitPanic {
+ toolkitPanic(a.ProgName)
+ break
+ }
+
// 99.9% of events are just widget changes
n := me.rootNode.findId(a.WidgetId)
if n != nil {
@@ -93,28 +121,6 @@ func watchCallback() {
log.Exit("wit/gui toolkit.UserQuit")
break
}
- if a.ActionType == widget.ToolkitPanic {
- log.Log(WARN, "guiChan() Toolkit panic() in", a.ProgName)
- log.Log(WARN, "guiChan() unload toolkit plugin here", a.ProgName)
- me.rootNode.ListToolkits()
- for _, aplug := range allPlugins {
- log.Log(WARN, "ListToolkits() already loaded toolkit plugin =", aplug.name)
- if aplug.name == a.ProgName {
- log.Log(WARN, "FOUND PLUGIN =", aplug.name)
- log.Log(WARN, "unload here")
- log.Log(WARN, "panic on purpose")
- me.rootNode.CloseToolkit(aplug.name)
- // panic("panic trapped!")
- // log.Sleep(.5)
- // me.rootNode.LoadToolkit("gocui")
- break
- }
- }
- log.UnsetTmp()
- // StandardExit()
- me.rootNode.LoadToolkit("nocui")
- break
- }
if a.ActionType == widget.ToolkitLoad {
newPlug := widget.GetString(a.Value)
log.Log(WARN, "Attempt to load a new toolkit", newPlug, "here")
diff --git a/plugin.go b/plugin.go
index 1f83c52..2f72c50 100644
--- a/plugin.go
+++ b/plugin.go
@@ -24,6 +24,10 @@ type aplug struct {
filename string
plug *plugin.Plugin
+ // set this to true if the plugin dies
+ // TODO: remove the plugin from the pool
+ dead bool
+
// this tells the toolkit plugin how to send events
// back here
//
@@ -269,6 +273,7 @@ func (n *Node) LoadToolkit(name string) *Node {
if plug == nil {
return n
}
+ plug.dead = false
log.Log(PLUG, "LoadToolkit() sending Toolkit Init action to the plugin channel")
var a widget.Action