forked from mojbro/gocoa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
application.m
41 lines (35 loc) · 1.02 KB
/
application.m
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
#import "application.h"
#import "appdelegate.h"
#include "_cgo_export.h"
AppDelegate *gocoa_applicationDelegate = nil;
// InitSharedApplication calls NSApplication.sharedApplication() which initializes the
// global application instance NSApp.
void InitSharedApplication() {
static bool hasBeenInitialized = false; // false first time function is called
if (hasBeenInitialized)
return;
[NSApplication sharedApplication];
gocoa_applicationDelegate = [[AppDelegate alloc] init];
[NSApp setDelegate:gocoa_applicationDelegate];
hasBeenInitialized = true;
}
void releaseSharedApplication() {
if (gocoa_applicationDelegate != nil) {
[gocoa_applicationDelegate release];
}
}
void RunApplication() {
@autoreleasepool {
[NSApp run];
releaseSharedApplication();
}
}
void TerminateApplication() {
[NSApp terminate:nil];
}
extern void go_callback(uintptr_t h);
void RunOnMainLoop(uintptr_t h) {
dispatch_async(dispatch_get_main_queue(), ^{
go_callback(h);
});
}