Changed the main thread signaling to use NSObject's performSelectorOnMainThread: functionality, which settles that. NSString requires an autorelease pool; in testing, so does NSValue, which we are eventually going to use. NSAutoreleasePool's docs suggest we should create a temporary pool for things running in other threads, but then we have to release it... but I guess we're waiting for the function to complete on other platforms already, so no big deal here.
This commit is contained in:
parent
6982912a58
commit
56a436bc80
|
@ -51,14 +51,9 @@ func buttonClicked(self C.id, sel C.SEL, sender C.id) {
|
|||
}
|
||||
|
||||
//export gotNotification
|
||||
func gotNotification(self C.id, sel C.SEL, note C.id) {
|
||||
data := C.objc_msgSend_noargs(note,
|
||||
sel_getUid("userInfo"))
|
||||
val := C.objc_msgSend_id(data,
|
||||
sel_getUid("objectForKey:"),
|
||||
notekey)
|
||||
func gotNotification(self C.id, sel C.SEL, object C.id) {
|
||||
source := (*C.char)(unsafe.Pointer(
|
||||
C.objc_msgSend_noargs(val,
|
||||
C.objc_msgSend_noargs(object,
|
||||
sel_getUid("UTF8String"))))
|
||||
fmt.Println("got notification from %s",
|
||||
C.GoString(source))
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
// id objc_msgSend_id_sel_id_id(id obj, SEL sel, id a, SEL b, id c, id d) { return objc_msgSend(obj, sel, a, b, c, d); }
|
||||
// id objc_msgSend_id_id_id(id obj, SEL sel, id a, id b, id c) { return objc_msgSend(obj, sel, a, b, c); }
|
||||
// id objc_msgSend_id_id(id obj, SEL sel, id a, id b) { return objc_msgSend(obj, sel, a, b); }
|
||||
// id objc_msgSend_sel_id_bool(id obj, SEL sel, SEL a, id b, BOOL c) { return objc_msgSend(obj, sel, a, b, c); }
|
||||
// Class NilClass = Nil; /* for newtypes.go */
|
||||
// id Nilid = nil;
|
||||
import "C"
|
||||
|
@ -49,8 +50,7 @@ func sel_getUid(sel string) C.SEL {
|
|||
var NSApp C.id
|
||||
var defNC C.id
|
||||
var delegate C.id
|
||||
var note C.id
|
||||
var notekey C.id
|
||||
var notesel C.SEL
|
||||
|
||||
func init() {
|
||||
// need an NSApplication first - see https://github.com/TooTallNate/NodObjC/issues/21
|
||||
|
@ -70,19 +70,7 @@ func init() {
|
|||
objc_getClass("hello"),
|
||||
alloc)
|
||||
|
||||
noteStr := []C.char{'g', 'o', 'n', 'o', 't', 'e', 0}
|
||||
note = C.objc_msgSend_strarg(
|
||||
objc_getClass("NSString"),
|
||||
sel_getUid("stringWithUTF8String:"),
|
||||
¬eStr[0])
|
||||
notekey = note
|
||||
C.objc_msgSend_id_sel_id_id(
|
||||
defNC,
|
||||
sel_getUid("addObserver:selector:name:object:"),
|
||||
delegate,
|
||||
selN,
|
||||
note,
|
||||
C.Nilid)
|
||||
notesel = selN
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -114,17 +102,12 @@ func notify(source string) {
|
|||
objc_getClass("NSString"),
|
||||
sel_getUid("stringWithUTF8String:"),
|
||||
csource)
|
||||
dict := C.objc_msgSend_id_id(
|
||||
objc_getClass("NSDictionary"),
|
||||
sel_getUid("dictionaryWithObject:forKey:"),
|
||||
C.objc_msgSend_sel_id_bool(
|
||||
delegate,
|
||||
sel_getUid("performSelectorOnMainThread:withObject:waitUntilDone:"),
|
||||
notesel,
|
||||
src,
|
||||
notekey)
|
||||
C.objc_msgSend_id_id_id(
|
||||
defNC,
|
||||
sel_getUid("postNotificationName:object:userInfo:"),
|
||||
note,
|
||||
C.Nilid,
|
||||
dict)
|
||||
C.BOOL(C.FALSE)) // don't wait; we're using a channel for this (in the final ui code)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in New Issue