summaryrefslogtreecommitdiff
path: root/uitask_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-30 22:48:12 -0400
committerPietro Gagliardi <[email protected]>2014-06-30 22:48:12 -0400
commitffa1bbe0b91a8c812ddcea5c5d65e55f60d07f33 (patch)
tree000fadd9af11843d92e7f0eee49fa90cca1379cd /uitask_darwin.go
parent990d50e9a153681a091a23734f8962e728fde1b0 (diff)
Restored the previous new API. I'm going to change it so that events are callbacks rather than using a window handler, but other than that... yeah.
Diffstat (limited to 'uitask_darwin.go')
-rw-r--r--uitask_darwin.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/uitask_darwin.go b/uitask_darwin.go
index 754418c..317cb12 100644
--- a/uitask_darwin.go
+++ b/uitask_darwin.go
@@ -4,7 +4,6 @@ package ui
import (
"fmt"
- "runtime"
"unsafe"
)
@@ -16,32 +15,31 @@ import "C"
var uitask chan func()
-func ui(main func()) error {
- runtime.LockOSThread()
-
- uitask = make(chan func())
-
+func uiinit() error {
err := initCocoa()
if err != nil {
return err
}
- // Cocoa must run on the first thread created by the program, so we run our dispatcher on another thread instead
- go func() {
- for f := range uitask {
- C.douitask(appDelegate, unsafe.Pointer(&f))
- }
- }()
+ // do this at the end in case something goes wrong
+ uitask = make(chan func())
+ return nil
+}
+func ui() {
+ // Cocoa must run on the first thread created by the program, so we run our dispatcher on another thread instead
go func() {
- main()
- uitask <- func() {
- C.breakMainLoop()
+ for {
+ select {
+ case f := <-uitask:
+ C.douitask(appDelegate, unsafe.Pointer(&f))
+ case <-Stop:
+ C.breakMainLoop()
+ }
}
}()
C.cocoaMainLoop()
- return nil
}
func initCocoa() (err error) {