Skip to content

Commit

Permalink
Merge pull request #28 from mohakshah/invertList
Browse files Browse the repository at this point in the history
Add an option to invert the whitelist operation mode
  • Loading branch information
dteoh authored Mar 11, 2018
2 parents 89f4cff + 0744af1 commit 2d21015
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions SlowQuitApps/SQAAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ BOOL shouldHandleCmdQ() {
if ([activeApp.bundleIdentifier isEqualToString:@"com.apple.finder"]) {
return NO;
}

BOOL invertList = [SQAPreferences invertList];
for (NSString *bundleId in [SQAPreferences whitelist]) {
if ([activeApp.bundleIdentifier isEqualToString:bundleId]) {
return NO;
return (invertList ? YES : NO);
}
}
return YES;
return (invertList ? NO : YES);
}

OSStatus cmdQHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData) {
Expand Down
2 changes: 1 addition & 1 deletion SlowQuitApps/SQAPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

+ (NSInteger)delay;
+ (NSArray<NSString *> *)whitelist;

+ (BOOL)invertList;
@end
9 changes: 8 additions & 1 deletion SlowQuitApps/SQAPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ @implementation SQAPreferences
+ (NSUserDefaults *)defaults {
static BOOL defaultsRegistered;
if (!defaultsRegistered) {
[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"delay": @1000, @"whitelist": @[]}];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"delay": @1000, @"whitelist": @[], @"invertList": @NO}];
defaultsRegistered = YES;
}
return [NSUserDefaults standardUserDefaults];
Expand All @@ -31,5 +31,12 @@ + (NSInteger)delay {
return whitelist;
}

+ (BOOL)invertList {
static BOOL invertList;
if (!invertList) {
invertList = [[self defaults] boolForKey:@"invertList"];
}
return invertList;
}

@end

0 comments on commit 2d21015

Please sign in to comment.