File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package gocoa
4
4
// #cgo LDFLAGS: -framework Cocoa
5
5
// #include "application.h"
6
6
import "C"
7
+ import "runtime/cgo"
7
8
8
9
var appDidFinishLaunchingFunc func ()
9
10
@@ -34,3 +35,16 @@ func callOnApplicationDidFinishLaunchingHandler() {
34
35
appDidFinishLaunchingFunc ()
35
36
}
36
37
}
38
+
39
+ //export go_callback
40
+ func go_callback (h C.uintptr_t ) {
41
+ hnd := cgo .Handle (h )
42
+ fn := hnd .Value ().(func ())
43
+ fn ()
44
+ hnd .Delete ()
45
+ }
46
+
47
+ func RunOnMainLoop (fn func ()) {
48
+ h := cgo .NewHandle (fn )
49
+ C .RunOnMainLoop (C .uintptr_t (h ))
50
+ }
Original file line number Diff line number Diff line change
1
+ #include < stdint.h>
1
2
#import < Cocoa/Cocoa.h>
2
3
3
4
void InitSharedApplication ();
4
5
void RunApplication ();
5
- void TerminateApplication ();
6
+ void TerminateApplication ();
7
+ void RunOnMainLoop (uintptr_t h);
Original file line number Diff line number Diff line change @@ -31,4 +31,11 @@ void RunApplication() {
31
31
32
32
void TerminateApplication () {
33
33
[NSApp terminate: nil ];
34
+ }
35
+
36
+ extern void go_callback (uintptr_t h);
37
+ void RunOnMainLoop (uintptr_t h) {
38
+ dispatch_async (dispatch_get_main_queue (), ^{
39
+ go_callback (h);
40
+ });
34
41
}
You can’t perform that action at this time.
0 commit comments