2024-01-17 23:54:19 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:27:19 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
// the _ means we only need this for the init()
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
|
|
|
)
|
|
|
|
|
|
|
|
var uiMainUndef bool = true
|
|
|
|
var uiMain sync.Once
|
|
|
|
var muAction sync.Mutex
|
|
|
|
|
2024-02-05 12:06:17 -06:00
|
|
|
func queueAction(n *tree.Node, atype widget.ActionType) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
newAction(n, atype)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueAdd(n *tree.Node) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
newAdd(n)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueSetTitle(n *tree.Node, s string) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
SetText(n, s)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueSetLabel(n *tree.Node, s string) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
SetText(n, s)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueSetText(n *tree.Node, s string) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
SetText(n, s)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueAddText(n *tree.Node, s string) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
AddText(n, s)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-07 06:58:13 -06:00
|
|
|
func queueSetChecked(n *tree.Node, b bool) {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
setChecked(n, b)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-09 03:44:21 -06:00
|
|
|
func queueToolkitClose() {
|
|
|
|
ui.QueueMain(func() {
|
|
|
|
ui.Quit()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-05 12:06:17 -06:00
|
|
|
/*
|
2024-01-17 23:54:19 -06:00
|
|
|
func queueMain(currentA widget.Action) {
|
2024-01-19 02:52:57 -06:00
|
|
|
// this never happends
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log("YAHOOOO Recovered in queueMain() application:", r)
|
2024-01-19 02:52:57 -06:00
|
|
|
log.Println("Recovered from panic:", r)
|
|
|
|
log.Println("Stack trace:")
|
|
|
|
debug.PrintStack()
|
|
|
|
me.myTree.SendToolkitPanic()
|
|
|
|
}
|
|
|
|
}()
|
2024-01-18 21:00:37 -06:00
|
|
|
// andlabs puts this inside the gofunction over there
|
|
|
|
// probably this should be changed around here
|
|
|
|
// and only andlabs stuff should be sent there?
|
|
|
|
// it's easier to code it this way however
|
|
|
|
// also, if it dies here, it get's caught
|
|
|
|
// usually, this is where it dies
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()")
|
2024-01-17 23:54:19 -06:00
|
|
|
ui.QueueMain(func() {
|
2024-01-18 21:00:37 -06:00
|
|
|
processAction(¤tA)
|
2024-01-17 23:54:19 -06:00
|
|
|
})
|
|
|
|
}
|
2024-02-05 12:06:17 -06:00
|
|
|
*/
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
func guiMain() {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "YAHOOOO Recovered in guiMain application:", r)
|
|
|
|
log.Log(WARN, "Recovered from panic:", r)
|
|
|
|
log.Log(WARN, "Stack trace:")
|
2024-01-17 23:54:19 -06:00
|
|
|
debug.PrintStack()
|
2024-01-19 02:52:57 -06:00
|
|
|
me.myTree.SendToolkitPanic()
|
2024-01-18 23:18:28 -06:00
|
|
|
return
|
2024-01-17 23:54:19 -06:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
ui.Main(func() {
|
2024-01-18 21:00:37 -06:00
|
|
|
// this is a bad hack for now.
|
|
|
|
// a better way would be to spawn ui.Main on the first actual window
|
|
|
|
// that is supposed to be displayed
|
|
|
|
placeholderUI()
|
2024-01-19 12:18:11 -06:00
|
|
|
|
|
|
|
// if nothing is working, run this instead to make
|
|
|
|
// sure you have something
|
|
|
|
// demoUI()
|
2024-01-17 23:54:19 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Init() {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Init() TODO: move init() to here")
|
2024-01-17 23:54:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
|
|
|
|
func init() {
|
|
|
|
log.Log(INFO, "Init() START")
|
|
|
|
log.Log(INFO, "Init()")
|
|
|
|
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
|
|
|
|
// log.Log(INFO, "init() Setting defaultBehavior = true")
|
2024-01-19 02:52:57 -06:00
|
|
|
// setDefaultBehavior(true)
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
me.myTree = tree.New()
|
|
|
|
me.myTree.PluginName = "andlabs"
|
2024-02-05 12:06:17 -06:00
|
|
|
// me.myTree.ActionFromChannel = queueMain
|
|
|
|
|
|
|
|
me.myTree.NodeAction = queueAction
|
|
|
|
me.myTree.Add = queueAdd
|
|
|
|
me.myTree.SetTitle = queueSetTitle
|
|
|
|
me.myTree.SetLabel = queueSetLabel
|
|
|
|
me.myTree.SetText = queueSetText
|
|
|
|
me.myTree.AddText = queueAddText
|
2024-02-07 06:58:13 -06:00
|
|
|
me.myTree.SetChecked = queueSetChecked
|
2024-02-09 03:44:21 -06:00
|
|
|
me.myTree.ToolkitClose = queueToolkitClose
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
// TODO: this is messed up. run ui.Main() from the first add? Initialize it with an empty thing first?
|
|
|
|
// fake out the OS toolkit by making a fake window. This is probably needed for macos & windows
|
|
|
|
// actually, this probably breaks the macos build
|
|
|
|
go guiMain()
|
|
|
|
}
|
2024-01-18 23:18:28 -06:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
}
|