From 789aa26066a7420a30fb88a3ec97f6b2cbed4563 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 5 Jun 2014 21:43:06 -0400 Subject: [PATCH] Fix infinite loop when enabling iCloud. [FIXED] When enabling iCloud and setting the local user defaults, we re-started enabling iCloud and updating local user defaults. --- MasterPassword/ObjC/Mac/MPMacAppDelegate.m | 30 +++++++++---------- .../ObjC/iOS/MPPasswordsViewController.m | 16 +++++----- .../ObjC/iOS/MPUsersViewController.m | 8 ++--- MasterPassword/ObjC/iOS/MPiOSAppDelegate.m | 14 ++++----- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m index b5dad96e..21047cca 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m @@ -290,21 +290,21 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [[NSNotificationCenter defaultCenter] addObserverForName:MPCheckConfigNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock: ^(NSNotification *note) { - self.rememberPasswordItem.state = [[MPConfig get].rememberLogin boolValue]? NSOnState: NSOffState; - self.savePasswordItem.state = [[MPMacAppDelegate get] activeUserForMainThread].saveKey? NSOnState: NSOffState; - self.dialogStyleRegular.state = ![[MPMacConfig get].dialogStyleHUD boolValue]? NSOnState: NSOffState; - self.dialogStyleHUD.state = [[MPMacConfig get].dialogStyleHUD boolValue]? NSOnState: NSOffState; - - if ([note.object isEqual:NSStringFromSelector( @selector(dialogStyleHUD) )]) { - if (![self.passwordWindow.window isVisible]) - self.passwordWindow = nil; - else { - [self.passwordWindow close]; - self.passwordWindow = nil; - [self showPasswordWindow:nil]; - } - } - }]; + NSString *key = note.object; + if (!key || [key isEqualToString:NSStringFromSelector( @selector( rememberLogin ) )]) + self.rememberPasswordItem.state = [[MPConfig get].rememberLogin boolValue]? NSOnState: NSOffState; + if (!key || [key isEqualToString:NSStringFromSelector( @selector( dialogStyleHUD ) )]) { + self.dialogStyleRegular.state = ![[MPMacConfig get].dialogStyleHUD boolValue]? NSOnState: NSOffState; + self.dialogStyleHUD.state = [[MPMacConfig get].dialogStyleHUD boolValue]? NSOnState: NSOffState; + if (![self.passwordWindow.window isVisible]) + self.passwordWindow = nil; + else { + [self.passwordWindow close]; + self.passwordWindow = nil; + [self showPasswordWindow:nil]; + } + } + }]; [self updateUsers]; // Global hotkey. diff --git a/MasterPassword/ObjC/iOS/MPPasswordsViewController.m b/MasterPassword/ObjC/iOS/MPPasswordsViewController.m index d8181aa4..654f2bec 100644 --- a/MasterPassword/ObjC/iOS/MPPasswordsViewController.m +++ b/MasterPassword/ObjC/iOS/MPPasswordsViewController.m @@ -64,7 +64,7 @@ [self registerObservers]; [self observeStore]; - [self updateFromConfig]; + [self updateConfigKey:nil]; [self updatePasswords]; } @@ -175,7 +175,8 @@ referenceSizeForHeaderInSection:(NSInteger)section { if (controller == _fetchedResultsController) { [self.passwordCollectionView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]]; - [self.passwordCollectionView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section]]; + if (![newIndexPath isEqual:indexPath]) + [self.passwordCollectionView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section]]; } } @@ -267,9 +268,9 @@ referenceSizeForHeaderInSection:(NSInteger)section { }]; }], [[NSNotificationCenter defaultCenter] - addObserverForName:MPCheckConfigNotification object:nil - queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { - [self updateFromConfig]; + addObserverForName:MPCheckConfigNotification object:nil queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) { + [self updateConfigKey:note.object]; }], ]; } @@ -311,9 +312,10 @@ referenceSizeForHeaderInSection:(NSInteger)section { [[NSNotificationCenter defaultCenter] removeObserver:_storeObserver]; } -- (void)updateFromConfig { +- (void)updateConfigKey:(NSString *)key { - self.passwordsSearchBar.keyboardType = [[MPiOSConfig get].dictationSearch boolValue]? UIKeyboardTypeDefault: UIKeyboardTypeURL; + if (!key || [key isEqualToString:NSStringFromSelector( @selector(dictationSearch) )]) + self.passwordsSearchBar.keyboardType = [[MPiOSConfig get].dictationSearch boolValue]? UIKeyboardTypeDefault: UIKeyboardTypeURL; } - (void)updatePasswords { diff --git a/MasterPassword/ObjC/iOS/MPUsersViewController.m b/MasterPassword/ObjC/iOS/MPUsersViewController.m index 12057bd4..9485901e 100644 --- a/MasterPassword/ObjC/iOS/MPUsersViewController.m +++ b/MasterPassword/ObjC/iOS/MPUsersViewController.m @@ -757,34 +757,34 @@ typedef NS_ENUM(NSUInteger, MPActiveUserState) { case MPActiveUserStateLogin: { dbg(@"activeUserState -> login"); self.entryLabel.text = strl( @"Enter your master password:" ); - self.entryField.text = nil; self.entryField.secureTextEntry = YES; self.entryField.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.entryField.text = nil; break; } case MPActiveUserStateUserName: { dbg(@"activeUserState -> userName"); self.entryLabel.text = strl( @"Enter your full name:" ); - self.entryField.text = nil; self.entryField.secureTextEntry = NO; self.entryField.autocapitalizationType = UITextAutocapitalizationTypeWords; + self.entryField.text = nil; break; } case MPActiveUserStateMasterPasswordChoice: { dbg(@"activeUserState -> masterPasswordChoice"); self.entryLabel.text = strl( @"Choose your master password:" ); - self.entryField.text = nil; self.entryField.secureTextEntry = YES; self.entryField.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.entryField.text = nil; break; } case MPActiveUserStateMasterPasswordConfirmation: { dbg(@"activeUserState -> masterPasswordConfirmation"); _masterPasswordChoice = self.entryField.text; self.entryLabel.text = strl( @"Confirm your master password:" ); - self.entryField.text = nil; self.entryField.secureTextEntry = YES; self.entryField.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.entryField.text = nil; break; } case MPActiveUserStateMinimized: diff --git a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m index 95b2c834..5b53e35d 100644 --- a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m +++ b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m @@ -93,17 +93,17 @@ err( @"During Analytics Setup: %@", exception ); } @try { - [[NSNotificationCenter defaultCenter] addObserverForName:MPCheckConfigNotification object:nil queue:nil usingBlock: - ^(NSNotification *note) { - [self updateFromConfig]; + [[NSNotificationCenter defaultCenter] addObserverForName:MPCheckConfigNotification object:nil queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) { + [self updateConfigKey:note.object]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:kIASKAppSettingChanged object:nil queue:nil usingBlock: ^(NSNotification *note) { - [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:note userInfo:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:note.object]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:NSUserDefaultsDidChangeNotification object:nil queue:nil usingBlock: ^(NSNotification *note) { - [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:note userInfo:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:nil]; }]; #ifdef ADHOC @@ -292,7 +292,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application { inf( @"Re-activated" ); - [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:application]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:nil]; [super applicationDidBecomeActive:application]; } @@ -475,7 +475,7 @@ [[NSNotificationCenter defaultCenter] postNotificationName:MPCheckConfigNotification object:NSStringFromSelector( configKey )]; } -- (void)updateFromConfig { +- (void)updateConfigKey:(NSString *)key { // iCloud enabled / disabled BOOL iCloudEnabled = [[MPiOSConfig get].iCloudEnabled boolValue];