forked from mojbro/gocoa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.go
50 lines (41 loc) · 1.14 KB
/
application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gocoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #include "application.h"
import "C"
import "runtime/cgo"
var appDidFinishLaunchingFunc func()
// InitApplication initializes the global application instance. Call this before using
// the rest of the gocoa package.
func InitApplication() {
C.InitSharedApplication()
}
// RunApplication launches the main Cocoa runloop.
func RunApplication() {
C.RunApplication()
}
// OnApplicationDidFinishLaunching - will be triggered after Application Launch is finished
func OnApplicationDidFinishLaunching(fn func()) {
appDidFinishLaunchingFunc = fn
}
// TerminateApplication - will be triggered, when the Application terminates
func TerminateApplication() {
C.TerminateApplication()
}
//export callOnApplicationDidFinishLaunchingHandler
func callOnApplicationDidFinishLaunchingHandler() {
if appDidFinishLaunchingFunc != nil {
appDidFinishLaunchingFunc()
}
}
//export go_callback
func go_callback(h C.uintptr_t) {
hnd := cgo.Handle(h)
fn := hnd.Value().(func())
fn()
hnd.Delete()
}
func RunOnMainLoop(fn func()) {
h := cgo.NewHandle(fn)
C.RunOnMainLoop(C.uintptr_t(h))
}