From c7ea23ddb6559030d0be98bff090bf919b0c4265 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 9 Feb 2024 09:29:55 -0600 Subject: gocui panic() loads nocui correctly Signed-off-by: Jeff Carr --- action.go | 6 +++++- main.go | 52 +++++++++++++++++++++++++++++----------------------- plugin.go | 5 +++++ 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 -- cgit v1.2.3