From 0813fb40d03fad2ac52fcf61f33fa4883622d4a1 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sun, 16 Jun 2013 12:39:52 -0400 Subject: [PATCH] Retire use of confinement concurrency type. [FIXED] Confinement concurrency type is just all sorts of buggy. --- External/RHStatusItemView | 2 +- .../OpenSource/GTL/GTLService.m | 2 +- MasterPassword/ObjC/MPAppDelegate_Shared.h | 2 +- MasterPassword/ObjC/MPAppDelegate_Shared.m | 4 +- MasterPassword/ObjC/MPAppDelegate_Store.h | 3 +- MasterPassword/ObjC/MPAppDelegate_Store.m | 27 +++++------- MasterPassword/ObjC/Mac/MPMacAppDelegate.m | 42 +++++++++---------- .../ObjC/Mac/MPPasswordWindowController.m | 20 ++++----- .../ObjC/iOS/MPElementListController.m | 14 +++---- .../ObjC/iOS/MPElementListSearchController.m | 2 +- .../ObjC/iOS/MPMainViewController.m | 32 +++++++------- .../ObjC/iOS/MPPreferencesViewController.m | 6 +-- .../ObjC/iOS/MPTypeViewController.m | 4 +- .../ObjC/iOS/MPUnlockViewController.m | 10 ++--- MasterPassword/ObjC/iOS/MPiOSAppDelegate.m | 8 ++-- .../project.pbxproj | 9 +--- 16 files changed, 87 insertions(+), 100 deletions(-) diff --git a/External/RHStatusItemView b/External/RHStatusItemView index fa01dea4..039dc04e 160000 --- a/External/RHStatusItemView +++ b/External/RHStatusItemView @@ -1 +1 @@ -Subproject commit fa01dea4ec70d12a8b2db48e26b50271451a16e1 +Subproject commit 039dc04e667199396765dd394b70e3f38f04ea33 diff --git a/External/google-plus-ios-sdk/OpenSource/GTL/GTLService.m b/External/google-plus-ios-sdk/OpenSource/GTL/GTLService.m index ad00bb1d..e91e9b0c 100644 --- a/External/google-plus-ios-sdk/OpenSource/GTL/GTLService.m +++ b/External/google-plus-ios-sdk/OpenSource/GTL/GTLService.m @@ -755,7 +755,7 @@ static NSString *ETagIfPresent(GTLObject *obj) { // Build up the array of RPC calls. NSMutableArray *rpcPayloads = [NSMutableArray arrayWithCapacity:numberOfQueries]; - NSMutableArray *requestIDs = [NSMutableSet setWithCapacity:numberOfQueries]; + NSMutableSet *requestIDs = [NSMutableSet setWithCapacity:numberOfQueries]; for (GTLQuery *query in queries) { NSString *methodName = query.methodName; NSDictionary *parameters = query.JSON; diff --git a/MasterPassword/ObjC/MPAppDelegate_Shared.h b/MasterPassword/ObjC/MPAppDelegate_Shared.h index a044a52a..d961130d 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Shared.h +++ b/MasterPassword/ObjC/MPAppDelegate_Shared.h @@ -19,7 +19,7 @@ + (instancetype)get; -- (MPUserEntity *)activeUserForThread; +- (MPUserEntity *)activeUserForMainThread; - (MPUserEntity *)activeUserInContext:(NSManagedObjectContext *)moc; - (void)setActiveUser:(MPUserEntity *)activeUser; diff --git a/MasterPassword/ObjC/MPAppDelegate_Shared.m b/MasterPassword/ObjC/MPAppDelegate_Shared.m index 5527f611..9ba72cbf 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Shared.m +++ b/MasterPassword/ObjC/MPAppDelegate_Shared.m @@ -24,9 +24,9 @@ #endif } -- (MPUserEntity *)activeUserForThread { +- (MPUserEntity *)activeUserForMainThread { - return [self activeUserInContext:[MPAppDelegate_Shared managedObjectContextForThreadIfReady]]; + return [self activeUserInContext:[MPAppDelegate_Shared managedObjectContextForMainThreadIfReady]]; } - (MPUserEntity *)activeUserInContext:(NSManagedObjectContext *)moc { diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.h b/MasterPassword/ObjC/MPAppDelegate_Store.h index f812caa1..b0dacec0 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.h +++ b/MasterPassword/ObjC/MPAppDelegate_Store.h @@ -20,12 +20,13 @@ typedef enum { @interface MPAppDelegate_Shared(Store) -+ (NSManagedObjectContext *)managedObjectContextForThreadIfReady; ++ (NSManagedObjectContext *)managedObjectContextForMainThreadIfReady; + (BOOL)managedObjectContextPerformBlock:(void (^)(NSManagedObjectContext *context))mocBlock; + (BOOL)managedObjectContextPerformBlockAndWait:(void (^)(NSManagedObjectContext *context))mocBlock; - (UbiquityStoreManager *)storeManager; +/** @param completion The block to execute after adding the element, executed from the main thread with the new element in the main MOC. */ - (void)addElementNamed:(NSString *)siteName completion:(void (^)(MPElementEntity *element))completion; - (MPElementEntity *)changeElement:(MPElementEntity *)element inContext:(NSManagedObjectContext *)context toType:(MPElementType)type; - (MPImportResult)importSites:(NSString *)importedSitesString diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.m b/MasterPassword/ObjC/MPAppDelegate_Store.m index 1a4a5a10..4bcf97b3 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.m +++ b/MasterPassword/ObjC/MPAppDelegate_Store.m @@ -39,19 +39,14 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext, #pragma mark - Core Data setup -+ (NSManagedObjectContext *)managedObjectContextForThreadIfReady { ++ (NSManagedObjectContext *)managedObjectContextForMainThreadIfReady { + NSAssert([[NSThread currentThread] isMainThread], @"Can only access main MOC from the main thread."); NSManagedObjectContext *mainManagedObjectContext = [[self get] mainManagedObjectContextIfReady]; - if (!mainManagedObjectContext) + if (!mainManagedObjectContext || ![[NSThread currentThread] isMainThread]) return nil; - if ([[NSThread currentThread] isMainThread]) - return mainManagedObjectContext; - NSManagedObjectContext - *threadManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType]; - threadManagedObjectContext.parentContext = mainManagedObjectContext; - - return threadManagedObjectContext; + return mainManagedObjectContext; } + (BOOL)managedObjectContextPerformBlock:(void (^)(NSManagedObjectContext *context))mocBlock { @@ -396,8 +391,8 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext, return; } - [MPAppDelegate_Shared managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) { - MPUserEntity *activeUser = [self activeUserInContext:moc]; + [MPAppDelegate_Shared managedObjectContextPerformBlock:^(NSManagedObjectContext *context) { + MPUserEntity *activeUser = [self activeUserInContext:context]; assert(activeUser); MPElementType type = activeUser.defaultType; @@ -406,22 +401,22 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext, NSString *typeEntityClassName = [MPAlgorithmDefault classNameOfType:type]; MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:typeEntityClassName - inManagedObjectContext:moc]; + inManagedObjectContext:context]; element.name = siteName; element.user = activeUser; element.type = type; element.lastUsed = [NSDate date]; element.version = MPAlgorithmDefaultVersion; - [moc saveToStore]; + [context saveToStore]; NSError *error = nil; - if (element.objectID.isTemporaryID && ![moc obtainPermanentIDsForObjects:@[ element ] error:&error]) + if (element.objectID.isTemporaryID && ![context obtainPermanentIDsForObjects:@[ element ] error:&error]) err(@"Failed to obtain a permanent object ID after creating new element: %@", error); NSManagedObjectID *elementOID = [element objectID]; dispatch_async( dispatch_get_main_queue(), ^{ - completion( (MPElementEntity *)[[MPAppDelegate_Shared managedObjectContextForThreadIfReady] objectRegisteredForID:elementOID] ); + completion( (MPElementEntity *)[[MPAppDelegate_Shared managedObjectContextForMainThreadIfReady] objectRegisteredForID:elementOID] ); } ); }]; } @@ -689,7 +684,7 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext, - (NSString *)exportSitesShowingPasswords:(BOOL)showPasswords { - MPUserEntity *activeUser = [self activeUserForThread]; + MPUserEntity *activeUser = [self activeUserForMainThread]; inf(@"Exporting sites, %@, for: %@", showPasswords? @"showing passwords": @"omitting passwords", activeUser.userID); // Header. diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m index cdc0f514..6643a190 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m @@ -66,8 +66,8 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [[self.usersItem submenu] removeItem:obj]; }]; - NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady]; - if (!moc) { + NSManagedObjectContext *context = [MPMacAppDelegate managedObjectContextForMainThreadIfReady]; + if (!context) { self.createUserItem.title = @"New User (Not ready)"; self.createUserItem.enabled = NO; self.createUserItem.toolTip = @"Please wait until the app is fully loaded."; @@ -83,7 +83,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven NSError *error = nil; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPUserEntity class] )]; fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"lastUsed" ascending:NO] ]; - NSArray *users = [moc executeFetchRequest:fetchRequest error:&error]; + NSArray *users = [context executeFetchRequest:fetchRequest error:&error]; if (!users) err(@"Failed to load users: %@", error); @@ -94,7 +94,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven @"Then give iCloud some time to sync the new user to your Mac."; } - MPUserEntity *activeUser = self.activeUserForThread; + MPUserEntity *activeUser = [self activeUserInContext:context]; for (MPUserEntity *user in users) { NSMenuItem *userItem = [[NSMenuItem alloc] initWithTitle:user.name action:@selector(selectUser:) keyEquivalent:@""]; [userItem setTarget:self]; @@ -113,8 +113,8 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [self signOutAnimated:NO]; NSError *error = nil; - NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady]; - self.activeUser = (MPUserEntity *)[moc existingObjectWithID:[item representedObject] error:&error]; + NSManagedObjectContext *context = [MPMacAppDelegate managedObjectContextForMainThreadIfReady]; + self.activeUser = (MPUserEntity *)[context existingObjectWithID:[item representedObject] error:&error]; if (error) err(@"While looking up selected user: %@", error); @@ -261,7 +261,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [[NSNotificationCenter defaultCenter] addObserverForName:MPCheckConfigNotification object:nil queue:nil usingBlock: ^(NSNotification *note) { self.rememberPasswordItem.state = [[MPConfig get].rememberLogin boolValue]? NSOnState: NSOffState; - self.savePasswordItem.state = [[MPMacAppDelegate get] activeUserForThread].saveKey? 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; @@ -283,13 +283,13 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven OSStatus status = InstallApplicationEventHandler(NewEventHandlerUPP( MPHotKeyHander ), GetEventTypeCount( hotKeyEvents ), hotKeyEvents, (__bridge void *)self, NULL); if (status != noErr) - err(@"Error installing application event handler: %d", status); + err(@"Error installing application event handler: %i", (int)status); status = RegisterEventHotKey( 35 /* p */, controlKey + cmdKey, MPShowHotKey, GetApplicationEventTarget(), 0, &hotKeyRef ); if (status != noErr) - err(@"Error registering 'show' hotkey: %d", status); + err(@"Error registering 'show' hotkey: %i", (int)status); status = RegisterEventHotKey( 35 /* p */, controlKey + optionKey + cmdKey, MPLockHotKey, GetApplicationEventTarget(), 0, &hotKeyRef ); if (status != noErr) - err(@"Error registering 'lock' hotkey: %d", status); + err(@"Error registering 'lock' hotkey: %i", (int)status); // Initial display. [NSApp activateIgnoringOtherApps:YES]; @@ -301,11 +301,9 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven BOOL reopenPasswordWindow = [self.passwordWindow.window isVisible]; - if (![[self activeUserForThread].objectID isEqual:activeUser.objectID]) { - [self.passwordWindow close]; - self.passwordWindow = nil; - [super setActiveUser:activeUser]; - } + [self.passwordWindow close]; + self.passwordWindow = nil; + [super setActiveUser:activeUser]; self.usersItem.state = NSMixedState; [[[self.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { @@ -325,7 +323,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven - (void)updateMenuItems { - MPUserEntity *activeUser = [self activeUserForThread]; + MPUserEntity *activeUser = [self activeUserForMainThread]; // if (!(self.showItem.enabled = ![self.passwordWindow.window isVisible])) { // self.showItem.title = @"Show (Showing)"; // self.showItem.toolTip = @"Master Password is already showing."; @@ -390,7 +388,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [NSApp activateIgnoringOtherApps:YES]; // If no user, can't activate. - if (![self activeUserForThread]) { + if (![self activeUserForMainThread]) { [[NSAlert alertWithMessageText:@"No User Selected" defaultButton:[PearlStrings get].commonButtonOkay alternateButton:nil otherButton:nil informativeTextWithFormat: @"Begin by selecting or creating your user from the status menu (●●●|) next to the clock."] @@ -444,17 +442,17 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { // Save changes in the application's managed object context before the application terminates. - NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady]; - if (!moc) + NSManagedObjectContext *context = [MPMacAppDelegate managedObjectContextForMainThreadIfReady]; + if (!context) return NSTerminateNow; - if (![moc commitEditing]) + if (![context commitEditing]) return NSTerminateCancel; - if (![moc hasChanges]) + if (![context hasChanges]) return NSTerminateNow; - [moc saveToStore]; + [context saveToStore]; return NSTerminateNow; } diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index 0e7225ba..bf602c48 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -43,7 +43,7 @@ [self setContent:@""]; [self.tipField setStringValue:@""]; - [self.userLabel setStringValue:PearlString( @"%@'s password for:", [[MPMacAppDelegate get] activeUserForThread].name )]; + [self.userLabel setStringValue:PearlString( @"%@'s password for:", [[MPMacAppDelegate get] activeUserForMainThread].name )]; [[MPMacAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) { // [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) { // if (![MPAlgorithmDefault migrateUser:[[MPMacAppDelegate get] activeUserInContext:moc]]) @@ -106,7 +106,7 @@ - (BOOL)ensureStoreLoaded { - if ([MPMacAppDelegate managedObjectContextForThreadIfReady]) { + if ([MPMacAppDelegate managedObjectContextForMainThreadIfReady]) { // Store loaded. if (self.loadingDataAlert.window) [NSApp endSheet:self.loadingDataAlert.window]; @@ -197,12 +197,12 @@ runModal]; if (returnCode_ == NSAlertDefaultReturn) { - [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) { - MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:moc]; + [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) { + MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:context]; activeUser.keyID = nil; [[MPMacAppDelegate get] forgetSavedKeyFor:activeUser]; [[MPMacAppDelegate get] signOutAnimated:YES]; - [moc saveToStore]; + [context saveToStore]; }]; } break; @@ -315,7 +315,7 @@ if (notification.object == self.typeField) { if ([self.typeField indexOfSelectedItem] < 0) return; - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; MPElementType selectedType = [self selectedType]; if (!activeElement || activeElement.type == selectedType || !(selectedType & MPElementTypeClassGenerated)) return; @@ -421,9 +421,9 @@ self.siteFieldPreventCompletion = NO; } -- (MPElementEntity *)activeElementForThread { +- (MPElementEntity *)activeElementForMainThread { - return [self activeElementInContext:[MPMacAppDelegate managedObjectContextForThreadIfReady]]; + return [self activeElementInContext:[MPMacAppDelegate managedObjectContextForMainThreadIfReady]]; } - (MPElementEntity *)activeElementInContext:(NSManagedObjectContext *)moc { @@ -453,9 +453,9 @@ NSString *siteName = [self.siteField stringValue]; [self.progressView startAnimation:nil]; - [self.backgroundQueue addOperationWithBlock:^{ + [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) { BOOL actionHandled = NO; - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementInContext:context]; NSString *content = [activeElement.content description]; NSString *typeName = [activeElement typeShortName]; if (!content) diff --git a/MasterPassword/ObjC/iOS/MPElementListController.m b/MasterPassword/ObjC/iOS/MPElementListController.m index ee661e80..0c53eb7e 100644 --- a/MasterPassword/ObjC/iOS/MPElementListController.m +++ b/MasterPassword/ObjC/iOS/MPElementListController.m @@ -28,15 +28,15 @@ NSAssert([[NSThread currentThread] isMainThread], @"The fetchedResultsController must be accessed from the main thread."); if (!_fetchedResultsControllerByLastUsed) { - NSManagedObjectContext *mainContext = [MPiOSAppDelegate managedObjectContextForThreadIfReady]; - if (!mainContext) + NSManagedObjectContext *context = [MPiOSAppDelegate managedObjectContextForMainThreadIfReady]; + if (!context) return nil; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )]; fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:NSStringFromSelector( @selector(lastUsed) ) ascending:NO] ]; [self configureFetchRequest:fetchRequest]; _fetchedResultsControllerByLastUsed = [[NSFetchedResultsController alloc] - initWithFetchRequest:fetchRequest managedObjectContext:mainContext sectionNameKeyPath:nil cacheName:nil]; + initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; _fetchedResultsControllerByLastUsed.delegate = self; } @@ -48,15 +48,15 @@ NSAssert([[NSThread currentThread] isMainThread], @"The fetchedResultsController must be accessed from the main thread."); if (!_fetchedResultsControllerByUses) { - NSManagedObjectContext *mainContext = [MPiOSAppDelegate managedObjectContextForThreadIfReady]; - if (!mainContext) + NSManagedObjectContext *context = [MPiOSAppDelegate managedObjectContextForMainThreadIfReady]; + if (!context) return nil; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )]; fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:NSStringFromSelector( @selector(uses_) ) ascending:NO] ]; [self configureFetchRequest:fetchRequest]; _fetchedResultsControllerByUses = [[NSFetchedResultsController alloc] - initWithFetchRequest:fetchRequest managedObjectContext:mainContext sectionNameKeyPath:nil cacheName:nil]; + initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; _fetchedResultsControllerByUses.delegate = self; } @@ -78,7 +78,7 @@ - (void)updateData { - MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserForThread]; + MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserInContext:self.fetchedResultsControllerByLastUsed.managedObjectContext]; if (!activeUser) { _fetchedResultsControllerByLastUsed = nil; _fetchedResultsControllerByUses = nil; diff --git a/MasterPassword/ObjC/iOS/MPElementListSearchController.m b/MasterPassword/ObjC/iOS/MPElementListSearchController.m index 27167546..1572a32e 100644 --- a/MasterPassword/ObjC/iOS/MPElementListSearchController.m +++ b/MasterPassword/ObjC/iOS/MPElementListSearchController.m @@ -193,7 +193,7 @@ NSString *query = [self.searchDisplayController.searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; cell.textLabel.text = query; cell.detailTextLabel.text = PearlString( @"New site: %@", - [MPAlgorithmDefault shortNameOfType:[[[MPiOSAppDelegate get] activeUserForThread] defaultType]] ); + [MPAlgorithmDefault shortNameOfType:[[[MPiOSAppDelegate get] activeUserForMainThread] defaultType]] ); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/MasterPassword/ObjC/iOS/MPMainViewController.m b/MasterPassword/ObjC/iOS/MPMainViewController.m index f6c8e882..e1b879c0 100644 --- a/MasterPassword/ObjC/iOS/MPMainViewController.m +++ b/MasterPassword/ObjC/iOS/MPMainViewController.m @@ -83,7 +83,7 @@ }]; [[NSNotificationCenter defaultCenter] addObserverForName:MPElementUpdatedNotification object:nil queue:nil usingBlock: ^void(NSNotification *note) { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (activeElement.type & MPElementTypeClassStored && ![[activeElement.content description] length]) [self showToolTip:@"Tap to set a password." withIcon:self.toolTipEditIcon]; if (activeElement.requiresExplicitMigration) @@ -109,7 +109,7 @@ }]; [[NSNotificationCenter defaultCenter] addObserverForName:USMStoreDidChangeNotification object:nil queue:nil usingBlock: ^(NSNotification *note) { - if (!self.activeElementForThread) + if (!self.activeElementForMainThread) [self didSelectElement:nil]; }]; @@ -118,8 +118,8 @@ - (void)viewWillAppear:(BOOL)animated { - MPElementEntity *activeElement = [self activeElementForThread]; - if (activeElement.user != [[MPiOSAppDelegate get] activeUserForThread]) + MPElementEntity *activeElement = [self activeElementForMainThread]; + if (activeElement.user != [[MPiOSAppDelegate get] activeUserForMainThread]) _activeElementOID = nil; self.searchDisplayController.searchBar.text = nil; @@ -197,7 +197,7 @@ return; } - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; [self setHelpChapter:activeElement? @"2": @"1"]; [self updateHelpHiddenAnimated:NO]; @@ -358,7 +358,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; NSString *error = [self.helpView stringByEvaluatingJavaScriptFromString: PearlString( @"setClass('%@');", activeElement.typeClassName )]; if (error.length) @@ -464,7 +464,7 @@ - (IBAction)copyContent { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; id content = activeElement.content; if (!content) // Nothing to copy. @@ -484,7 +484,7 @@ - (IBAction)copyLoginName:(UITapGestureRecognizer *)sender { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (!activeElement.loginName) return; @@ -531,7 +531,7 @@ if (sender.state != UIGestureRecognizerStateBegan) // Only fire when the gesture was first detected. return; - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (![activeElement isKindOfClass:[MPElementGeneratedEntity class]]) { // Not of a type that supports a password counter. err(@"Cannot reset password counter: Element is not generated: %@", activeElement.name); @@ -563,7 +563,7 @@ // Only fire when the gesture was first detected. return; - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (!activeElement) return; @@ -621,9 +621,9 @@ }]; } -- (MPElementEntity *)activeElementForThread { +- (MPElementEntity *)activeElementForMainThread { - return [self activeElementInContext:[MPiOSAppDelegate managedObjectContextForThreadIfReady]]; + return [self activeElementInContext:[MPiOSAppDelegate managedObjectContextForMainThreadIfReady]]; } - (MPElementEntity *)activeElementInContext:(NSManagedObjectContext *)moc { @@ -641,7 +641,7 @@ - (IBAction)editPassword { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (!(activeElement.type & MPElementTypeClassStored)) { // Not of a type that supports editing the content. err(@"Cannot edit content: Element is not stored: %@", activeElement.name); @@ -659,7 +659,7 @@ - (IBAction)upgradePassword { - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (!activeElement) return; @@ -779,7 +779,7 @@ - (MPElementEntity *)selectedElement { - return [self activeElementForThread]; + return [self activeElementForMainThread]; } - (void)didSelectType:(MPElementType)type { @@ -855,7 +855,7 @@ if (textField == self.contentField) { self.contentField.enabled = NO; - MPElementEntity *activeElement = [self activeElementForThread]; + MPElementEntity *activeElement = [self activeElementForMainThread]; if (![activeElement isKindOfClass:[MPElementStoredEntity class]]) { // Not of a type whose content can be edited. err(@"Cannot update element content: Element is not stored: %@", activeElement.name); diff --git a/MasterPassword/ObjC/iOS/MPPreferencesViewController.m b/MasterPassword/ObjC/iOS/MPPreferencesViewController.m index 481de820..58b0a621 100644 --- a/MasterPassword/ObjC/iOS/MPPreferencesViewController.m +++ b/MasterPassword/ObjC/iOS/MPPreferencesViewController.m @@ -53,7 +53,7 @@ }]; } } options:0]; - avatar.selected = (a == [[MPiOSAppDelegate get] activeUserForThread].avatar); + avatar.selected = (a == [[MPiOSAppDelegate get] activeUserForMainThread].avatar); } [super viewDidLoad]; @@ -70,7 +70,7 @@ } } recurse:NO]; - MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserForThread]; + MPUserEntity *activeUser = [[MPiOSAppDelegate get] activeUserForMainThread]; self.savePasswordSwitch.on = activeUser.saveKey; self.defaultTypeLabel.text = [[MPiOSAppDelegate get].key.algorithm shortNameOfType:activeUser.defaultType]; @@ -154,7 +154,7 @@ - (MPElementType)selectedType { - return [[MPiOSAppDelegate get] activeUserForThread].defaultType; + return [[MPiOSAppDelegate get] activeUserForMainThread].defaultType; } #pragma mark - IBActions diff --git a/MasterPassword/ObjC/iOS/MPTypeViewController.m b/MasterPassword/ObjC/iOS/MPTypeViewController.m index b7780462..7d50a234 100644 --- a/MasterPassword/ObjC/iOS/MPTypeViewController.m +++ b/MasterPassword/ObjC/iOS/MPTypeViewController.m @@ -73,7 +73,7 @@ MPElementType selectedType = selectedElement? selectedElement.type: [self.delegate selectedType]; cell.selected = (selectedType == cellType); - if (cellType != NSNotFound && cellType & MPElementTypeClassGenerated) { + if (cellType != (MPElementType)NSNotFound && cellType & MPElementTypeClassGenerated) { [(UITextField *)[cell viewWithTag:2] setText:@"..."]; NSString *name = selectedElement.name; @@ -99,7 +99,7 @@ assert(self.navigationController.topViewController == self); MPElementType type = [self typeAtIndexPath:indexPath]; - if (type == NSNotFound) + if (type == (MPElementType)NSNotFound) // Selected a non-type row. return; diff --git a/MasterPassword/ObjC/iOS/MPUnlockViewController.m b/MasterPassword/ObjC/iOS/MPUnlockViewController.m index ec08639a..f9c7df04 100644 --- a/MasterPassword/ObjC/iOS/MPUnlockViewController.m +++ b/MasterPassword/ObjC/iOS/MPUnlockViewController.m @@ -369,11 +369,11 @@ NSAssert([[NSThread currentThread] isMainThread], @"User selection should only be toggled from the main thread."); - NSManagedObjectContext *mainContext = [MPiOSAppDelegate managedObjectContextForThreadIfReady]; - MPUserEntity *selectedUser = [self selectedUserInContext:mainContext]; + NSManagedObjectContext *context = [MPiOSAppDelegate managedObjectContextForMainThreadIfReady]; + MPUserEntity *selectedUser = [self selectedUserInContext:context]; if (!selectedUser) [self.passwordField resignFirstResponder]; - else if ([[MPiOSAppDelegate get] signInAsUser:selectedUser saveInContext:mainContext usingMasterPassword:nil]) { + else if ([[MPiOSAppDelegate get] signInAsUser:selectedUser saveInContext:context usingMasterPassword:nil]) { [self performSegueWithIdentifier:@"MP_Unlock" sender:self]; return; } @@ -556,7 +556,7 @@ UIButton *targetedAvatar = selectedAvatar; if (!targetedAvatar) { targetedAvatar = [self findTargetedAvatar]; - targetedUser = [self userForAvatar:targetedAvatar inContext:[MPiOSAppDelegate managedObjectContextForThreadIfReady]]; + targetedUser = [self userForAvatar:targetedAvatar inContext:[MPiOSAppDelegate managedObjectContextForMainThreadIfReady]]; } [self.avatarsView enumerateSubviews:^(UIView *subview, BOOL *stop, BOOL *recurse) { @@ -1140,7 +1140,7 @@ - (MPUserEntity *)selectedUserForThread { - return [self selectedUserInContext:[MPiOSAppDelegate managedObjectContextForThreadIfReady]]; + return [self selectedUserInContext:[MPiOSAppDelegate managedObjectContextForMainThreadIfReady]]; } - (MPUserEntity *)selectedUserInContext:(NSManagedObjectContext *)moc { diff --git a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m index 987e2d2e..55ede2c4 100644 --- a/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m +++ b/MasterPassword/ObjC/iOS/MPiOSAppDelegate.m @@ -491,7 +491,7 @@ - (void)openFeedbackWithLogs:(BOOL)logs forVC:(UIViewController *)viewController { - NSString *userName = [[MPiOSAppDelegate get] activeUserForThread].name; + NSString *userName = [[MPiOSAppDelegate get] activeUserForMainThread].name; PearlLogLevel logLevel = PearlLogLevelInfo; if (logs && ([[MPiOSConfig get].sendInfo boolValue] || [[MPiOSConfig get].traceMode boolValue])) logLevel = PearlLogLevelDebug; @@ -566,7 +566,7 @@ @"--\n" @"%@\n" @"Master Password %@, build %@", - [self activeUserForThread].name, + [self activeUserForMainThread].name, [PearlInfoPlist get].CFBundleShortVersionString, [PearlInfoPlist get].CFBundleVersion ); else @@ -574,7 +574,7 @@ @"--\n" @"%@\n" @"Master Password %@, build %@", - [self activeUserForThread].name, + [self activeUserForMainThread].name, [PearlInfoPlist get].CFBundleShortVersionString, [PearlInfoPlist get].CFBundleVersion ); @@ -584,7 +584,7 @@ [PearlEMail sendEMailTo:nil subject:@"Master Password Export" body:message attachments:[[PearlEMailAttachment alloc] initWithContent:[exportedSites dataUsingEncoding:NSUTF8StringEncoding] mimeType:@"text/plain" fileName: - PearlString( @"%@ (%@).mpsites", [self activeUserForThread].name, + PearlString( @"%@ (%@).mpsites", [self activeUserForMainThread].name, [exportDateFormatter stringFromDate:[NSDate date]] )], nil]; } diff --git a/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj b/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj index d5e98067..00cab776 100644 --- a/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj +++ b/MasterPassword/ObjC/iOS/MasterPassword-iOS.xcodeproj/project.pbxproj @@ -230,7 +230,6 @@ DABD3C201711E2DC00CF925C /* MPUnlockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DABD3BEF1711E2DC00CF925C /* MPUnlockViewController.m */; }; DABD3C211711E2DC00CF925C /* MPiOSConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = DABD3BF11711E2DC00CF925C /* MPiOSConfig.m */; }; DABD3C221711E2DC00CF925C /* MainStoryboard_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DABD3BF21711E2DC00CF925C /* MainStoryboard_iPhone.storyboard */; }; - DABD3C231711E2DC00CF925C /* MasterPassword-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DABD3BF31711E2DC00CF925C /* MasterPassword-Info.plist */; }; DABD3C241711E2DC00CF925C /* MasterPassword.entitlements in Resources */ = {isa = PBXBuildFile; fileRef = DABD3BF81711E2DC00CF925C /* MasterPassword.entitlements */; }; DABD3C251711E2DC00CF925C /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = DABD3BF91711E2DC00CF925C /* Settings.bundle */; }; DABD3C261711E2DC00CF925C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = DABD3BFA1711E2DC00CF925C /* InfoPlist.strings */; }; @@ -3258,7 +3257,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = MP; - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = Lyndir; }; buildConfigurationList = DA5BFA3E147E415C00F98B1E /* Build configuration list for PBXProject "MasterPassword-iOS" */; @@ -3517,7 +3516,6 @@ DABD3B9E1711E29800CF925C /* social-twitter@2x.png in Resources */, DABD3C191711E2DC00CF925C /* MPElementListCellView.xib in Resources */, DABD3C221711E2DC00CF925C /* MainStoryboard_iPhone.storyboard in Resources */, - DABD3C231711E2DC00CF925C /* MasterPassword-Info.plist in Resources */, DABD3C241711E2DC00CF925C /* MasterPassword.entitlements in Resources */, DABD3C251711E2DC00CF925C /* Settings.bundle in Resources */, DABD3C261711E2DC00CF925C /* InfoPlist.strings in Resources */, @@ -3857,7 +3855,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MasterPassword.app/MasterPassword"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; @@ -3887,7 +3884,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MasterPassword.app/MasterPassword"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; @@ -3971,7 +3967,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_WARN_CXX0X_EXTENSIONS = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -4041,7 +4036,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_WARN_CXX0X_EXTENSIONS = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -4166,7 +4160,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_WARN_CXX0X_EXTENSIONS = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES;