summaryrefslogtreecommitdiff
path: root/uitask_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
committerPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
commit33155f7496a818a1ed83fe49cccb63be7842bc81 (patch)
treebbb14af3d92becf7d5ca5abfb28630a2b413ad93 /uitask_darwin.go
parente032807546a96e6489d18a0e42ced51b7c31a55c (diff)
Reverted everything back to the old API.
Diffstat (limited to 'uitask_darwin.go')
-rw-r--r--uitask_darwin.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/uitask_darwin.go b/uitask_darwin.go
index 317cb12..754418c 100644
--- a/uitask_darwin.go
+++ b/uitask_darwin.go
@@ -4,6 +4,7 @@ package ui
import (
"fmt"
+ "runtime"
"unsafe"
)
@@ -15,31 +16,32 @@ import "C"
var uitask chan func()
-func uiinit() error {
+func ui(main func()) error {
+ runtime.LockOSThread()
+
+ uitask = make(chan func())
+
err := initCocoa()
if err != nil {
return err
}
- // 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() {
- for {
- select {
- case f := <-uitask:
- C.douitask(appDelegate, unsafe.Pointer(&f))
- case <-Stop:
- C.breakMainLoop()
- }
+ for f := range uitask {
+ C.douitask(appDelegate, unsafe.Pointer(&f))
+ }
+ }()
+
+ go func() {
+ main()
+ uitask <- func() {
+ C.breakMainLoop()
}
}()
C.cocoaMainLoop()
+ return nil
}
func initCocoa() (err error) {