forked from koekeishiya/yabai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.m
49 lines (39 loc) · 1.47 KB
/
loader.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
42
43
44
45
46
47
48
49
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import "common.h"
static Class _instance;
OSErr yabai_osax_load(const AppleEvent *event, AppleEvent *reply, long context)
{
NSLog(@"[yabai] attempting to load scripting addition..");
OSErr result = OSAX_PAYLOAD_SUCCESS;
NSBundle *loader_bundle = [NSBundle bundleWithIdentifier:@"com.koekeishiya.yabai-osax"];
NSLog(@"[yabai] loader_bundle: %@", loader_bundle);
NSString *payload_path = [loader_bundle pathForResource:@"payload" ofType:@"bundle"];
NSLog(@"[yabai] payload_path: %@", payload_path);
NSBundle *payload_bundle = [NSBundle bundleWithPath:payload_path];
NSLog(@"[yabai] payload_bundle: %@", payload_bundle);
if (!payload_bundle) {
NSLog(@"[yabai] could not locate payload!");
result = OSAX_PAYLOAD_NOT_FOUND;
goto end;
}
if ([payload_bundle isLoaded]) {
NSLog(@"[yabai] payload has already been loaded!");
result = OSAX_PAYLOAD_ALREADY_LOADED;
goto end;
}
if (![payload_bundle load]) {
NSLog(@"[yabai] could not load payload!");
result = OSAX_PAYLOAD_NOT_LOADED;
goto end;
}
_instance = [payload_bundle principalClass];
NSLog(@"[yabai] set class instance: %@", _instance);
end:
if (result == OSAX_PAYLOAD_SUCCESS) {
NSLog(@"[yabai] scripting addition loaded successfully..");
} else {
NSLog(@"[yabai] failed to load scriping addition!");
}
return result;
}