Skip to content

Commit

Permalink
Add blacklist feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetrich committed Dec 26, 2011
1 parent a589eb1 commit 35597e7
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 4 deletions.
11 changes: 11 additions & 0 deletions 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
75 changes: 75 additions & 0 deletions 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
10 changes: 9 additions & 1 deletion 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>

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions LASpringBoardActivator.x
Expand Up @@ -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
Expand Down Expand Up @@ -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:)];
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions libactivator.h
Expand Up @@ -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;
Expand Down
26 changes: 24 additions & 2 deletions libactivator.x
Expand Up @@ -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];
Expand All @@ -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])
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 35597e7

Please sign in to comment.