Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add blacklist feature

  • Loading branch information...
commit 35597e7719315c5ccac5bfed31f6f4b03c80bf60 1 parent a589eb1
@rpetrich authored
View
11 LABlacklistSettingsController.h
@@ -0,0 +1,11 @@
+#import "Settings.h"
+
+__attribute__((visibility("hidden")))
+@interface LABlacklistSettingsController : LASettingsViewController {
+@private
+ NSString *systemAppsTitle;
+ NSArray *systemApps;
+ NSString *userAppsTitle;
+ NSArray *userApps;
+}
+@end
View
75 LABlacklistSettingsController.m
@@ -0,0 +1,75 @@
+#import "LABlacklistSettingsController.h"
+
+#import "libactivator-private.h"
+
+@implementation LABlacklistSettingsController
+
+- (id)init
+{
+ if ((self = [super init])) {
+ self.navigationItem.title = [LASharedActivator localizedStringForKey:@"BLACKLIST" value:@"Blacklist"];
+ // Should actually retrieve application list directly, but this works
+ NSDictionary *listeners = [LASharedActivator _cachedAndSortedListeners];
+ systemAppsTitle = [[LASharedActivator localizedStringForKey:@"LISTENER_GROUP_TITLE_System Applications" value:@"System Applications"] retain];
+ systemApps = [[listeners objectForKey:systemAppsTitle] retain];
+ userAppsTitle = [[LASharedActivator localizedStringForKey:@"LISTENER_GROUP_TITLE_User Applications" value:@"User Applications"] retain];
+ userApps = [[listeners objectForKey:userAppsTitle] retain];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [userApps release];
+ [userAppsTitle release];
+ [systemApps release];
+ [systemAppsTitle release];
+ [super dealloc];
+}
+
+- (void)loadView
+{
+ [super loadView];
+ _tableView.rowHeight = 44.0f;
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return [userApps count] ? 2 : 1;
+}
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+ return section ? userAppsTitle : systemAppsTitle;
+}
+
+- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
+{
+ return [section ? userApps : systemApps count];
+}
+
+- (NSString *)displayIdentifierForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return [indexPath.section ? userApps : systemApps objectAtIndex:indexPath.row];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"] ?: [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
+ NSString *displayIdentifier = [self displayIdentifierForRowAtIndexPath:indexPath];
+ cell.textLabel.text = [LASharedActivator localizedTitleForListenerName:displayIdentifier];
+ cell.imageView.image = [LASharedActivator smallIconForListenerName:displayIdentifier];
+ cell.accessoryType = [LASharedActivator applicationWithDisplayIdentifierIsBlacklisted:displayIdentifier] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
+ NSString *displayIdentifier = [self displayIdentifierForRowAtIndexPath:indexPath];
+ BOOL blacklisted = ![LASharedActivator applicationWithDisplayIdentifierIsBlacklisted:displayIdentifier];
+ [LASharedActivator setApplicationWithDisplayIdentifier:displayIdentifier isBlacklisted:blacklisted];
+ [tableView cellForRowAtIndexPath:indexPath].accessoryType = blacklisted ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+}
+
+@end
View
10 LARootSettingsController.m
@@ -1,6 +1,7 @@
#import "Settings.h"
#import "libactivator-private.h"
#import "LAMenuSettingsController.h"
+#import "LABlacklistSettingsController.h"
#include <dlfcn.h>
#include <notify.h>
@@ -43,7 +44,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
case 1:
return [[LASharedActivator availableEventModes] count];
case 2:
- return 3;
+ return 4;
case 3:
return libhideIsHidden ? 2 : 1;
default:
@@ -100,6 +101,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.textLabel.text = [LASharedActivator localizedStringForKey:@"MENUS" value:@"Menus"];
cell.detailTextLabel.text = [LASharedActivator localizedStringForKey:@"MENUS_DETAIL" value:@"Manage custom Activator menus"];
break;
+ case 3:
+ cell.textLabel.text = [LASharedActivator localizedStringForKey:@"BLACKLIST" value:@"Blacklist"];
+ cell.detailTextLabel.text = [LASharedActivator localizedStringForKey:@"BLACKLIST_DETAIL" value:@"Ignore events in specific applications"];
+ break;
}
break;
case 3:
@@ -157,6 +162,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
case 2:
vc = [[LAMenuSettingsController alloc] init];
break;
+ case 3:
+ vc = [[LABlacklistSettingsController alloc] init];
+ break;
default:
return;
}
View
8 LASpringBoardActivator.x
@@ -337,6 +337,13 @@ static void NewCydiaStatusChanged()
return [[LAApplicationListener sharedInstance] topApplication] ? LAEventModeApplication : LAEventModeSpringBoard;
}
+- (NSString *)displayIdentifierForCurrentApplication
+{
+ if ([(SpringBoard *)UIApp isLocked] || [[%c(SBAwayController) sharedAwayController] isMakingEmergencyCall])
+ return nil;
+ return [[[LAApplicationListener sharedInstance] topApplication] displayIdentifier];
+}
+
// Events
- (NSArray *)availableEventNames
@@ -444,6 +451,7 @@ static void NewCydiaStatusChanged()
[messagingCenter registerForMessageName:@"isAlive" target:self selector:@selector(_handleRemoteIsAlive)];
[messagingCenter registerForMessageName:@"_cachedAndSortedListeners" target:self selector:@selector(_handleRemoteMessage:withUserInfo:)];
[messagingCenter registerForMessageName:@"currentEventMode" target:self selector:@selector(_handleRemoteMessage:withUserInfo:)];
+ [messagingCenter registerForMessageName:@"displayIdentifierForCurrentApplication" target:self selector:@selector(_handleRemoteMessage:withUserInfo:)];
[messagingCenter registerForMessageName:@"availableListenerNames" target:self selector:@selector(_handleRemoteMessage:withUserInfo:)];
[messagingCenter registerForMessageName:@"availableEventNames" target:self selector:@selector(_handleRemoteMessage:withUserInfo:)];
[messagingCenter registerForMessageName:@"eventWithNameIsHidden:" target:self selector:@selector(_handleRemoteBoolMessage:withUserInfo:)];
View
2  Makefile
@@ -12,7 +12,7 @@ libactivator_FRAMEWORKS = UIKit CoreGraphics QuartzCore
libactivator_PRIVATE_FRAMEWORKS = AppSupport GraphicsServices
# Settings.dylib (/Library/Activator)
-Settings_FILES = LAListenerSettingsViewController.m LASettingsViewController.m LAWebSettingsController.m LARootSettingsController.m LAModeSettingsController.m LAEventSettingsController.m LAEventGroupSettingsController.m LAMenuSettingsController.m LAMenuItemsController.m LAMenuListenerSelectionController.m ActivatorEventViewHeader.m LAListenerTableViewDataSource.m
+Settings_FILES = LAListenerSettingsViewController.m LASettingsViewController.m LAWebSettingsController.m LARootSettingsController.m LAModeSettingsController.m LAEventSettingsController.m LAEventGroupSettingsController.m LAMenuSettingsController.m LAMenuItemsController.m LAMenuListenerSelectionController.m ActivatorEventViewHeader.m LAListenerTableViewDataSource.m LABlacklistSettingsController.m
Settings_INSTALL_PATH = /Library/Activator
Settings_FRAMEWORKS = UIKit CoreGraphics QuartzCore
Settings_LDFLAGS = -L$(FW_OBJ_DIR) -lactivator
View
6 libactivator.h
@@ -114,6 +114,12 @@ typedef enum {
@property (nonatomic, readonly) NSArray *availableEventModes;
@property (nonatomic, readonly) NSString *currentEventMode;
+// Blacklisting
+
+@property (nonatomic, readonly) NSString *displayIdentifierForCurrentApplication;
+- (BOOL)applicationWithDisplayIdentifierIsBlacklisted:(NSString *)displayIdentifier;
+- (void)setApplicationWithDisplayIdentifier:(NSString *)displayIdentifier isBlacklisted:(BOOL)blacklisted;
+
@end
extern LAActivator *LASharedActivator;
View
26 libactivator.x
@@ -262,8 +262,9 @@ static UIAlertView *inCydiaAlert;
NSString *listenerName = [self assignedListenerNameForEvent:event];
if (listenerName && [self listenerWithName:listenerName isCompatibleWithEventName:[event name]]) {
if ([self isDangerousToSendEvents]) {
- if (![[event name] isEqualToString:LAEventNameMenuPressSingle] &&
- ![[event name] isEqualToString:LAEventNameMenuPressDouble]
+ NSString *eventName = event.name;
+ if (![eventName isEqualToString:LAEventNameMenuPressSingle] &&
+ ![eventName isEqualToString:LAEventNameMenuPressDouble]
) {
if (!inCydiaAlert) {
inCydiaAlert = [[UIAlertView alloc] init];
@@ -277,6 +278,11 @@ static UIAlertView *inCydiaAlert;
NSLog(@"Activator: sendEventToListener:%@ (listener=%@) aborted in Cydia", event, listenerName);
return;
}
+ NSString *displayIdentifier = self.displayIdentifierForCurrentApplication;
+ if (displayIdentifier && [self applicationWithDisplayIdentifierIsBlacklisted:displayIdentifier]) {
+ NSLog(@"Activator: sendEventToListener:%@ (listener=%@) aborted in blacklisted app \"%@\"", event, listenerName, displayIdentifier);
+ return;
+ }
id<LAListener> listener = [self listenerForName:listenerName];
[listener activator:self receiveEvent:event forListenerName:listenerName];
if ([event isHandled])
@@ -528,6 +534,22 @@ static UIAlertView *inCydiaAlert;
return [self _performRemoteMessage:_cmd withObject:nil];
}
+- (NSString *)displayIdentifierForCurrentApplication
+{
+ return [self _performRemoteMessage:_cmd withObject:nil];
+}
+
+- (BOOL)applicationWithDisplayIdentifierIsBlacklisted:(NSString *)displayIdentifier
+{
+ return [[self _getObjectForPreference:[@"LABlacklisted-" stringByAppendingString:displayIdentifier]] boolValue];
+}
+
+- (void)setApplicationWithDisplayIdentifier:(NSString *)displayIdentifier isBlacklisted:(BOOL)blacklisted
+{
+ if (displayIdentifier)
+ [self _setObject:blacklisted ? (id)kCFBooleanTrue : nil forPreference:[@"LABlacklisted-" stringByAppendingString:displayIdentifier]];
+}
+
- (NSString *)description
{
return [NSString stringWithFormat:@"<LAActivator listenerCount=%d eventCount=%d %p>", [[self availableListenerNames] count], [[self availableEventNames] count], self];
Please sign in to comment.
Something went wrong with that request. Please try again.