-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFLEXitListener.m
51 lines (40 loc) · 1.66 KB
/
FLEXitListener.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
50
51
#import <libactivator/libactivator.h>
#import <objc/runtime.h>
#import <notify.h>
#import "Sources/FLEXManager.h"
@interface SBApplication
- (NSString *)bundleIdentifier;
@end
@interface SpringBoard
- (SBApplication *)_accessibilityFrontMostApplication;
@end
@interface SBLockScreenManager : NSObject
+ (instancetype)sharedInstance;
- (BOOL)isUILocked;
@end
@interface FLEXitListener : NSObject <LAListener>
@end
@implementation FLEXitListener
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event forListenerName:(NSString *)listenerName {
SBApplication *frontmostApp = [(SpringBoard *)UIApplication.sharedApplication _accessibilityFrontMostApplication];
SBLockScreenManager *lockscreenManager = [objc_getClass("SBLockScreenManager") sharedInstance];
if (frontmostApp && !lockscreenManager.isUILocked) {
notify_post([[NSString stringWithFormat:@"com.ipadkid.flexit/%@", frontmostApp.bundleIdentifier] UTF8String]);
} else {
[FLEXManager.sharedManager showExplorer];
}
}
+ (void)load {
NSString *currentID = NSBundle.mainBundle.bundleIdentifier;
if ([currentID isEqualToString:@"com.apple.springboard"]) {
// This string just needs to match whatever is in layout/Library/Activator/Listeners
[LAActivator.sharedInstance registerListener:self.new forName:@"com.ipadkid.flexit"];
} else {
int regToken;
NSString *notifForBundle = [NSString stringWithFormat:@"com.ipadkid.flexit/%@", currentID];
notify_register_dispatch(notifForBundle.UTF8String, ®Token, dispatch_get_main_queue(), ^(int token) {
[FLEXManager.sharedManager showExplorer];
});
}
}
@end