Created
July 18, 2016 20:54
-
-
Save NSExceptional/74d3c3a8b92126c53d3e495ce98dd820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Tweak.m | |
// FLEXing | |
// | |
// Created by Tanner Bennett on 2016-07-11 | |
// Copyright © 2016 Tanner Bennett. All rights reserved. | |
// | |
#import "Interfaces.h" | |
@interface FLEXingActivatorListenerInstance : NSObject <LAListener> | |
@end | |
@implementation FLEXingActivatorListenerInstance | |
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event forListenerName:(NSString *)listenerName { | |
NSString *frontmostAppID = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityFrontMostApplication].bundleIdentifier; | |
// [[FLEXManager sharedManager] toggleExplorer]; | |
// event.handled = YES; | |
if ([listenerName isEqualToString:kFLEXingShow] && !frontmostAppID) { | |
[[FLEXManager sharedManager] showExplorer]; | |
} else if ([listenerName isEqualToString:kFLEXingToggle] && !frontmostAppID) { | |
[[FLEXManager sharedManager] toggleExplorer]; | |
} else { | |
event.handled = NO; | |
return; | |
} | |
if (frontmostAppID) { | |
Alert(@"Springboard", nil); | |
// Send message on messaging center | |
CPDistributedMessagingCenter *c = [%c(CPDistributedMessagingCenter) centerNamed:kFLEXingMessagingCenter]; | |
[c sendMessageName:listenerName userInfo:nil]; | |
// event.handled = YES; | |
} else { | |
event.handled = YES; | |
} | |
} | |
- (NSArray *)activator:(LAActivator *)activator requiresCompatibleEventModesForListenerWithName:(NSString *)listenerName { | |
return @[@"springboard", @"lockscreen", @"application"]; | |
} | |
@end | |
%hook UIApplication | |
- (id)init { | |
NSString *displayID = [self displayIdentifier]; | |
// Register activator handlers in springboard | |
if ([displayID isEqualToString:@"com.apple.springboard"]) { | |
FLEXingActivatorListenerInstance *FLEXALI = [FLEXingActivatorListenerInstance new]; | |
[[LAActivator sharedInstance] registerListener:FLEXALI forName:kFLEXingShow]; | |
[[LAActivator sharedInstance] registerListener:FLEXALI forName:kFLEXingToggle]; | |
// Start messaging server | |
CPDistributedMessagingCenter *c = [%c(CPDistributedMessagingCenter) centerNamed:kFLEXingMessagingCenter]; | |
rocketbootstrap_distributedmessagingcenter_apply(c); | |
[c runServerOnCurrentThread]; | |
} else { | |
// Register for messaging server events | |
CPDistributedMessagingCenter *c = [%c(CPDistributedMessagingCenter) centerNamed:kFLEXingMessagingCenter]; | |
rocketbootstrap_distributedmessagingcenter_apply(c); | |
[c registerForMessageName:kFLEXingToggle target:[FLEXManager sharedManager] selector:@selector(showExplorer)]; | |
} | |
return %orig; | |
} | |
%end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment