summaryrefslogtreecommitdiff
path: root/andlabs/main.go
blob: 5a6d383626d4dba5600cd82b83c9a73c63d071d1 (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
package main

import (
	"sync"
	"go.wit.com/log"
	"go.wit.com/gui/widget"

	"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

func queueMain(currentA widget.Action) {
	defer func() {
		if r := recover(); r != nil {
			log.Warn("YAHOOOO Recovered in main application:", r)
		}
	}()
	ui.QueueMain( func() {
		rawAction(&currentA)
	})
}

func catchActionChannel() {
	log.Log(INFO, "catchActionChannel() START")
	for {
		log.Log(INFO, "catchActionChannel() for loop")
	    	select {
		case a := <-pluginChan:
			log.Log(INFO, "catchActionChannel() SELECT widget id =", a.WidgetId, a.ProgName)
			log.Log(INFO, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
			muAction.Lock()
			// TODO ui.QueueMain(f)
			// TODO ui.QueueMain( func() {rawAction(a)} )
			// rawAction(a)
			queueMain(a)
			muAction.Unlock()
			log.Log(INFO, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
		}
	}
}

func guiMain() {
	defer func() {
		if r := recover(); r != nil {
			log.Warn("YAHOOOO Recovered in main application:", r)
		}
	}()
	ui.Main(func() {
		demoUI()
	})
}

// 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")
	setDefaultBehavior(true)

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

	// andlabs = make(map[int]*andlabsT)
	pluginChan = make(chan widget.Action, 1)

	log.Log(INFO, "Init() start channel reciever")
	go catchActionChannel()
	log.Log(INFO, "Init() END")
}