-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFScriptLoader.m
More file actions
100 lines (82 loc) 路 3.63 KB
/
Copy pathFScriptLoader.m
File metadata and controls
100 lines (82 loc) 路 3.63 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// FScriptLoader.m
// FScriptLoader
//
// Created by Wolfgang Baird on 2/4/18.
//Copyright 漏 2018 Wolfgang Baird. All rights reserved.
//
@import AppKit;
@interface FScriptMenuItem : NSMenuItem
- (IBAction)openObjectBrowser:(id)sender;
- (IBAction)showConsole:(id)sender;
- (IBAction)showPreferencePanel:(id)sender;
- (IBAction)updatePreference:(id)sender;
- (void)insertInMainMenu;
@end
@interface FScriptLoader : NSObject {
id eventMonitor;
NSMenuItem* menuItem;
}
+(void) load;
+(FScriptLoader*) sharedInstance;
@end
@implementation FScriptLoader
+ (instancetype)sharedInstance{
static FScriptLoader *plugin = nil;
@synchronized(self) {
if (!plugin) {
plugin = [[self alloc] init];
}
}
return plugin;
}
+ (void)load {
NSLog(@"fscriptloader : %@", NSBundle.mainBundle.bundleIdentifier);
NSArray *blackList = [[NSArray alloc] initWithObjects:@"com.apple.dock", @"com.apple.loginwindow", nil];
NSUInteger osx_ver = [[NSProcessInfo processInfo] operatingSystemVersion].minorVersion;
if (![blackList containsObject:NSBundle.mainBundle.bundleIdentifier]) {
// Load F-Script
NSString *FScript = [NSString stringWithFormat:@"%@/Contents/Frameworks/FScript.framework", [[NSBundle bundleWithIdentifier:@"org.w0lf.FScriptLoader"] bundlePath]];
[[NSBundle bundleWithPath:FScript] load];
// Setup keywatch
FScriptLoader* plugin = [FScriptLoader sharedInstance];
// Add menuitem into main menu
[NSClassFromString(@"FScriptMenuItem") performSelector:@selector(insertInMainMenu)];
// Log
NSLog(@"%@ loaded into %@ on macOS 10.%ld", [self class], [[NSBundle mainBundle] bundleIdentifier], (long)osx_ver);
} else {
NSLog(@"%@ aborted loading into %@ on macOS 10.%ld", [self class], [[NSBundle mainBundle] bundleIdentifier], (long)osx_ver);
}
}
-(id) init {
self = [super init];
if( !self ) return nil;
menuItem = [NSClassFromString(@"FScriptMenuItem").alloc init];
[NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:^(NSEvent *event){
if ([event modifierFlags] == 1704234 && [event keyCode] == 8) {
/*CMD, ALT, SHIFT + C*/
[self->menuItem performSelector:@selector(showConsole:) withObject:nil];
} else if ([event modifierFlags] == 1704234 && [event keyCode] == 31) {
[self->menuItem performSelector:@selector(openObjectBrowser:) withObject:nil];
}
}];
NSEvent * (^monitorHandler)(NSEvent *);
monitorHandler = ^NSEvent * (NSEvent * event){
if ([event modifierFlags] == 1704234 && [event keyCode] == 8) {
/*CMD, ALT, SHIFT + C*/
[self->menuItem performSelector:@selector(showConsole:) withObject:nil];
return nil;
} else if ([event modifierFlags] == 1704234 && [event keyCode] == 31) {
[self->menuItem performSelector:@selector(openObjectBrowser:) withObject:nil];
return nil;
}
// Return the event, a new event, or, to stop
// the event from being dispatched, nil
return event;
};
eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:monitorHandler];
return self;
}
@end