From 990d50e9a153681a091a23734f8962e728fde1b0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 30 Jun 2014 22:42:48 -0400 Subject: Rolled back all those changes; I'm stupid. --- uitask_darwin.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'uitask_darwin.go') diff --git a/uitask_darwin.go b/uitask_darwin.go index 5932cac..754418c 100644 --- a/uitask_darwin.go +++ b/uitask_darwin.go @@ -14,25 +14,30 @@ import ( // #include "objc_darwin.h" import "C" -// can be run from any thread -// will wait for return; see delegateuitask_darwin.m -func uitask(f func()) { - C.douitask(appDelegate, unsafe.Pointer(&f)) -} +var uitask chan func() func ui(main func()) error { runtime.LockOSThread() + uitask = make(chan func()) + 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)) + } + }() + go func() { main() - uitask(func() { + uitask <- func() { C.breakMainLoop() - }) + } }() C.cocoaMainLoop() -- cgit v1.2.3