summaryrefslogtreecommitdiff
path: root/init.go
blob: a2a31983a15c4f6508d03eb028e6892f57206e4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// plugin
package main

import (
	"runtime/debug"
	"sync"
	"time"

	"go.wit.com/log"
	"go.wit.com/toolkits/tree"

	"go.wit.com/dev/andlabs/ui"
	// the _ means we only need this for the init()
	_ "go.wit.com/dev/andlabs/ui/winmanifest"
)

// sent via -ldflags
var VERSION string
var BUILDTIME string

var PLUGIN string = "andlabs"

var uiMainUndef bool = true
var uiMain sync.Once
var muAction sync.Mutex

/*
func newaction(n *tree.Node, atype widget.ActionType) {
	ui.QueueMain(func() {
		newAction(n, atype)
	})
}
*/

func queueAdd(n *tree.Node) {
	ui.QueueMain(func() {
		newAdd(n)
	})
}

func enableWidget(n *tree.Node) {
	ui.QueueMain(func() {
		realEnable(n, true)
	})
}

func disableWidget(n *tree.Node) {
	ui.QueueMain(func() {
		realEnable(n, false)
	})
}

func setTitle(n *tree.Node, s string) {
	ui.QueueMain(func() {
		SetText(n, s)
	})
}

func setLabel(n *tree.Node, s string) {
	ui.QueueMain(func() {
		realSetText(n, s)
	})
}

func setText(n *tree.Node, s string) {
	ui.QueueMain(func() {
		realSetText(n, s)
	})
}

func addText(n *tree.Node, s string) {
	ui.QueueMain(func() {
		realAddText(n, s)
	})
}

func setChecked(n *tree.Node, b bool) {
	ui.QueueMain(func() {
		realSetChecked(n, b)
	})
}

func toolkitClose() {
	ui.QueueMain(func() {
		ui.Quit()
	})
}

/*
func queueMain(currentA widget.Action) {
		// this never happends
		defer func() {
			if r := recover(); r != nil {
				log.Log("YAHOOOO Recovered in queueMain() application:", r)
				log.Println("Recovered from panic:", r)
				log.Println("Stack trace:")
				debug.PrintStack()
				me.myTree.SendToolkitPanic()
			}
		}()
	// 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
	log.Log(ANDLABS, "about to send action into the andlabs ui.QueueMain()")
	ui.QueueMain(func() {
		processAction(&currentA)
	})
}
*/

func guiMain() {
	defer func() {
		if r := recover(); r != nil {
			log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
			log.Log(WARN, "Stack trace:")
			debug.PrintStack()
			log.Log(WARN, "Recovered from panic:", r)
			log.Log(WARN, "andlabs GUI recovered in guiMain()")
			log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
			me.myTree.SendToolkitPanic()
			return
		}
	}()

	// TODO: THIS IS THE PROBLEM
	ui.Main(func() {
		// 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
		if r := recover(); r != nil {
			log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
			log.Log(WARN, "Stack trace:")
			debug.PrintStack()
			log.Log(WARN, "Recovered from panic:", r)
			log.Log(WARN, "andlabs GUI recovered in guiMain()")
			log.Log(WARN, "YAHOO andlabs GUI recovered in guiMain()")
			me.myTree.SendToolkitPanic()
			return
		}
		time.Sleep(time.Second)
		placeholderUI()

		me.myTree.InitOK()

		// if nothing is working, run this instead to make
		// sure you have something
		// demoUI()
	})
}

func Init() {
	log.Log(WARN, "Init() TODO: move init() to here")
}

// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func initPlugin() {
	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")
	// setDefaultBehavior(true)

	me.myTree = initTree()

	// me.ok = true // this tells init() it's okay to work with gocui
	/*
		me.myTree = tree.New()
		me.myTree.PluginName = "andlabs"
		// 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
		me.myTree.SetChecked = queueSetChecked
		me.myTree.ToolkitClose = queueToolkitClose
	*/

	// 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()
}

func main() {
}