Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NSExceptional/74d3c3a8b92126c53d3e495ce98dd820 to your computer and use it in GitHub Desktop.
Save NSExceptional/74d3c3a8b92126c53d3e495ce98dd820 to your computer and use it in GitHub Desktop.
//
// 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