diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.h b/MasterPassword/ObjC/Mac/MPMacAppDelegate.h index dc8d2255..7dd2d338 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.h +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.h @@ -25,7 +25,7 @@ @property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleRegular; @property(nonatomic, weak) IBOutlet NSMenuItem *dialogStyleHUD; -- (IBAction)showPasswordWindow; +- (IBAction)showPasswordWindow:(id)sender; - (IBAction)togglePreference:(NSMenuItem *)sender; - (IBAction)newUser:(NSMenuItem *)sender; - (IBAction)lock:(id)sender; diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m index 2c5401a0..f1e49940 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m @@ -40,7 +40,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven // Check which hotkey this was. if (hotKeyID.signature == MPShowHotKey.signature && hotKeyID.id == MPShowHotKey.id) { - [((__bridge MPMacAppDelegate *)userData) showPasswordWindow]; + [((__bridge MPMacAppDelegate *)userData) showPasswordWindow:nil]; return noErr; } if (hotKeyID.signature == MPLockHotKey.signature && hotKeyID.id == MPLockHotKey.id) { @@ -168,7 +168,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self updateUsers]; [self setActiveUser:newUser]; - [self showPasswordWindow]; + [self showPasswordWindow:nil]; }]; }]; } @@ -238,7 +238,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven else { [self.passwordWindow close]; self.passwordWindow = nil; - [self showPasswordWindow]; + [self showPasswordWindow:nil]; } } }]; @@ -280,24 +280,24 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven [MPMacConfig get].usedUserName = activeUser.name; if (reopenPasswordWindow) - [self showPasswordWindow]; + [self showPasswordWindow:nil]; } - (void)updateMenuItems { MPUserEntity *activeUser = [self activeUserForThread]; - if (!(self.showItem.enabled = ![self.passwordWindow.window isVisible])) { - self.showItem.title = @"Show (Showing)"; - self.showItem.toolTip = @"Master Password is already showing."; - } - else if (!(self.showItem.enabled = (activeUser != nil))) { - self.showItem.title = @"Show (No user)"; - self.showItem.toolTip = @"First select the user to show passwords for."; - } - else { - self.showItem.title = @"Show"; - self.showItem.toolTip = nil; - } +// if (!(self.showItem.enabled = ![self.passwordWindow.window isVisible])) { +// self.showItem.title = @"Show (Showing)"; +// self.showItem.toolTip = @"Master Password is already showing."; +// } +// else if (!(self.showItem.enabled = (activeUser != nil))) { +// self.showItem.title = @"Show (No user)"; +// self.showItem.toolTip = @"First select the user to show passwords for."; +// } +// else { +// self.showItem.title = @"Show"; +// self.showItem.toolTip = nil; +// } if (self.key) { self.lockItem.title = @"Lock"; @@ -346,7 +346,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven // [self showPasswordWindow]; } -- (IBAction)showPasswordWindow { +- (IBAction)showPasswordWindow:(id)sender { // If no user, can't activate. if (![self activeUserForThread]) diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index d95db01a..55cc7244 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -14,6 +14,7 @@ #define MPAlertUnlockMP @"MPAlertUnlockMP" #define MPAlertIncorrectMP @"MPAlertIncorrectMP" #define MPAlertCreateSite @"MPAlertCreateSite" +#define MPAlertLoadingData @"MPAlertLoadingData" @interface MPPasswordWindowController() @@ -21,6 +22,7 @@ @property(nonatomic) BOOL siteFieldPreventCompletion; @property(nonatomic, strong) NSOperationQueue *backgroundQueue; +@property(nonatomic, strong) NSConditionLock *loadingLock; @end @implementation MPPasswordWindowController { @@ -41,7 +43,7 @@ [self.tipField setStringValue:@""]; [self.userLabel setStringValue:PearlString( @"%@'s password for:", [[MPMacAppDelegate get] activeUserForThread].name )]; -// [[MPMacAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) { + [[MPMacAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) { // [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) { // if (![MPAlgorithmDefault migrateUser:[[MPMacAppDelegate get] activeUserInContext:moc]]) // [NSAlert alertWithMessageText:@"Migration Needed" defaultButton:@"OK" alternateButton:nil otherButton:nil @@ -50,18 +52,23 @@ // @"their passwords to change. You'll need to update your profile for that site with the new password."]; // [moc saveToStore]; // }]; -// } forKeyPath:@"key" options:NSKeyValueObservingOptionInitial context:nil]; + if (!self.inProgress && ![MPMacAppDelegate get].key) { + if (![MPMacAppDelegate get].activeUserForThread.saveKey) + [self unlock]; + else + [self.window close]; + } + } forKeyPath:@"key" options:NSKeyValueObservingOptionInitial context:nil]; [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowDidBecomeKeyNotification object:self.window queue:nil usingBlock:^(NSNotification *note) { - if (![MPMacAppDelegate managedObjectContextForThreadIfReady]) - [self waitUntilStoreLoaded]; + [self waitUntilStoreLoaded]; if (!self.inProgress) [self unlock]; - [self.siteField selectText:self]; + [self.siteField selectText:nil]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification object:self.window queue:nil usingBlock:^(NSNotification *note) { - [[NSApplication sharedApplication] hide:self]; + [[NSApplication sharedApplication] hide:nil]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:MPSignedOutNotification object:nil queue:nil usingBlock:^(NSNotification *note) { @@ -77,6 +84,18 @@ } - (void)waitUntilStoreLoaded { + + if ([MPMacAppDelegate managedObjectContextForThreadIfReady]) { + [self.loadingLock unlockWithCondition:1]; + return; + } + + [[NSAlert alertWithMessageText:@"Loading Your Data" defaultButton:nil alternateButton:nil otherButton:nil + informativeTextWithFormat:nil] + beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) + contextInfo:MPAlertLoadingData]; + [self.loadingLock = [[NSConditionLock alloc] initWithCondition:0] lockWhenCondition:1]; + self.loadingLock = nil; } - (void)unlock { @@ -123,6 +142,11 @@ [self.window close]; return; } + if (contextInfo == MPAlertLoadingData) { + [alert.window orderOut:nil]; + [self waitUntilStoreLoaded]; + return; + } if (contextInfo == MPAlertUnlockMP) { switch (returnCode) { case NSAlertAlternateReturn: { diff --git a/MasterPassword/ObjC/Mac/en.lproj/MainMenu.xib b/MasterPassword/ObjC/Mac/en.lproj/MainMenu.xib index 591cf723..e94c1898 100644 --- a/MasterPassword/ObjC/Mac/en.lproj/MainMenu.xib +++ b/MasterPassword/ObjC/Mac/en.lproj/MainMenu.xib @@ -272,7 +272,8 @@ Quit - + q + 1048576 2147483647 @@ -307,14 +308,6 @@ 726 - - - showItem - - - - 730 - statusMenu @@ -445,11 +438,19 @@ - showPasswordWindow + showPasswordWindow: - 781 + 782 + + + + showItem + + + + 783 @@ -708,13 +709,13 @@ - 781 + 783 MPAppDelegate_Shared - PearlAppDelegate + NSObject IBProjectSource ./Classes/MPAppDelegate_Shared.h @@ -724,17 +725,13 @@ MPMacAppDelegate MPAppDelegate_Shared - id id NSMenuItem id + id NSMenuItem - - activate: - id - lock: id @@ -747,6 +744,10 @@ rebuildCloud: id + + showPasswordWindow: + id + togglePreference: NSMenuItem @@ -811,44 +812,6 @@ ./Classes/MPMacAppDelegate.h - - PearlAppDelegate - UIResponder - - UINavigationController - UIWindow - - - - navigationController - UINavigationController - - - window - UIWindow - - - - IBProjectSource - ./Classes/PearlAppDelegate.h - - - - UINavigationController - UIViewController - - IBProjectSource - ./Classes/UINavigationController.h - - - - UIWindow - UIView - - IBProjectSource - ./Classes/UIWindow.h - - 0