2
0

Alert display issues fixed.

[FIXED]     Alert display issues.
[FIXED]     Access to activeUser from a different thread.
This commit is contained in:
Maarten Billemont 2013-05-16 00:59:32 -04:00
parent d7f369350b
commit 9904fb2d57
3 changed files with 162 additions and 32 deletions

View File

@ -18,5 +18,6 @@
@property(nonatomic, weak) IBOutlet NSTextField *userLabel; @property(nonatomic, weak) IBOutlet NSTextField *userLabel;
- (void)unlock; - (void)unlock;
- (IBAction)reload:(id)sender;
@end @end

View File

@ -14,7 +14,6 @@
#define MPAlertUnlockMP @"MPAlertUnlockMP" #define MPAlertUnlockMP @"MPAlertUnlockMP"
#define MPAlertIncorrectMP @"MPAlertIncorrectMP" #define MPAlertIncorrectMP @"MPAlertIncorrectMP"
#define MPAlertCreateSite @"MPAlertCreateSite" #define MPAlertCreateSite @"MPAlertCreateSite"
#define MPAlertLoadingData @"MPAlertLoadingData"
@interface MPPasswordWindowController() @interface MPPasswordWindowController()
@ -22,7 +21,7 @@
@property(nonatomic) BOOL siteFieldPreventCompletion; @property(nonatomic) BOOL siteFieldPreventCompletion;
@property(nonatomic, strong) NSOperationQueue *backgroundQueue; @property(nonatomic, strong) NSOperationQueue *backgroundQueue;
@property(nonatomic, strong) NSConditionLock *loadingLock; @property(nonatomic, strong) NSAlert *loadingDataAlert;
@end @end
@implementation MPPasswordWindowController { @implementation MPPasswordWindowController {
@ -52,18 +51,11 @@
// @"their passwords to change. You'll need to update your profile for that site with the new password."]; // @"their passwords to change. You'll need to update your profile for that site with the new password."];
// [moc saveToStore]; // [moc saveToStore];
// }]; // }];
if (!self.inProgress && ![MPMacAppDelegate get].key) { [self handleUnloadedOrLocked];
if (![MPMacAppDelegate get].activeUserForThread.saveKey)
[self unlock];
else
[self.window close];
}
} forKeyPath:@"key" options:NSKeyValueObservingOptionInitial context:nil]; } forKeyPath:@"key" options:NSKeyValueObservingOptionInitial context:nil];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserverForName:NSWindowDidBecomeKeyNotification object:self.window queue:nil usingBlock:^(NSNotification *note) { addObserverForName:NSWindowDidBecomeKeyNotification object:self.window queue:nil usingBlock:^(NSNotification *note) {
[self waitUntilStoreLoaded]; [self checkLoadedAndUnlocked];
if (!self.inProgress)
[self unlock];
[self.siteField selectText:nil]; [self.siteField selectText:nil];
}]; }];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -73,35 +65,55 @@
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserverForName:MPSignedOutNotification object:nil queue:nil usingBlock:^(NSNotification *note) { addObserverForName:MPSignedOutNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
_activeElementOID = nil; _activeElementOID = nil;
[self.window close]; [self.siteField setStringValue:@""];
[self trySiteWithAction:NO];
[self handleUnloadedOrLocked];
}]; }];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserverForName:USMStoreDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) { addObserverForName:USMStoreDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[self waitUntilStoreLoaded]; [self checkLoadedAndUnlocked];
}]; }];
[super windowDidLoad]; [super windowDidLoad];
} }
- (void)waitUntilStoreLoaded { - (void)handleUnloadedOrLocked {
if (!self.inProgress && ![MPMacAppDelegate get].key) {
MPUserEntity *activeUser = [MPMacAppDelegate get].activeUserForThread;
if (activeUser && !activeUser.saveKey)
[self unlock];
else
[self.window close];
}
}
- (void)checkLoadedAndUnlocked {
if ([self waitUntilStoreLoaded] && !self.inProgress)
[self unlock];
}
- (BOOL)waitUntilStoreLoaded {
if ([MPMacAppDelegate managedObjectContextForThreadIfReady]) { if ([MPMacAppDelegate managedObjectContextForThreadIfReady]) {
[self.loadingLock unlockWithCondition:1]; [NSApp endSheet:self.loadingDataAlert.window];
return; return YES;
} }
[[NSAlert alertWithMessageText:@"Loading Your Data" defaultButton:nil alternateButton:nil otherButton:nil [self.loadingDataAlert = [NSAlert alertWithMessageText:@"Opening Your Data" defaultButton:@"..." alternateButton:nil otherButton:nil
informativeTextWithFormat:nil] informativeTextWithFormat:@""]
beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) beginSheetModalForWindow:self.window modalDelegate:self
contextInfo:MPAlertLoadingData]; didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
[self.loadingLock = [[NSConditionLock alloc] initWithCondition:0] lockWhenCondition:1];
self.loadingLock = nil; return NO;
} }
- (void)unlock { - (void)unlock {
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) { [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:moc]; MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:moc];
NSString *userName = activeUser.name;
if (!activeUser) if (!activeUser)
// No user to sign in with. // No user to sign in with.
return; return;
@ -125,7 +137,7 @@
NSAlert *alert = [NSAlert alertWithMessageText:@"Master Password is locked." NSAlert *alert = [NSAlert alertWithMessageText:@"Master Password is locked."
defaultButton:@"Unlock" alternateButton:@"Change" otherButton:@"Cancel" defaultButton:@"Unlock" alternateButton:@"Change" otherButton:@"Cancel"
informativeTextWithFormat:@"The master password is required to unlock the application for:\n\n%@", informativeTextWithFormat:@"The master password is required to unlock the application for:\n\n%@",
activeUser.name]; userName];
NSSecureTextField *passwordField = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )]; NSSecureTextField *passwordField = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
[alert setAccessoryView:passwordField]; [alert setAccessoryView:passwordField];
[alert layout]; [alert layout];
@ -136,17 +148,17 @@
}]; }];
} }
- (IBAction)reload:(id)sender {
[[MPMacAppDelegate get].storeManager reloadStore];
}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (contextInfo == MPAlertIncorrectMP) { if (contextInfo == MPAlertIncorrectMP) {
[self.window close]; [self.window close];
return; return;
} }
if (contextInfo == MPAlertLoadingData) {
[alert.window orderOut:nil];
[self waitUntilStoreLoaded];
return;
}
if (contextInfo == MPAlertUnlockMP) { if (contextInfo == MPAlertUnlockMP) {
switch (returnCode) { switch (returnCode) {
case NSAlertAlternateReturn: { case NSAlertAlternateReturn: {
@ -355,7 +367,9 @@
- (void)trySiteWithAction:(BOOL)doAction { - (void)trySiteWithAction:(BOOL)doAction {
NSString *siteName = [self.siteField stringValue]; NSString *siteName = [self.siteField stringValue];
[self.progressView startAnimation:nil];
[self.backgroundQueue addOperationWithBlock:^{ [self.backgroundQueue addOperationWithBlock:^{
BOOL actionHandled = NO;
NSString *content = [[self activeElementForThread].content description]; NSString *content = [[self activeElementForThread].content description];
if (!content) if (!content)
content = @""; content = @"";
@ -369,15 +383,18 @@
else if ([siteName length]) { else if ([siteName length]) {
// Performing action without content but a site name is written. // Performing action without content but a site name is written.
[self createNewSite:siteName]; [self createNewSite:siteName];
return; actionHandled = YES;
} }
} }
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self setContent:content]; [self setContent:content];
[self.progressView stopAnimation:nil];
self.tipField.alphaValue = 1; self.tipField.alphaValue = 1;
if ([content length] == 0) { if (actionHandled)
[self.tipField setStringValue:@""];
else if ([content length] == 0) {
if ([siteName length]) if ([siteName length])
[self.tipField setStringValue:@"Hit ⌤ (ENTER) to create a new site."]; [self.tipField setStringValue:@"Hit ⌤ (ENTER) to create a new site."];
else else

View File

@ -12,6 +12,8 @@
</object> </object>
<array key="IBDocument.IntegratedClassDependencies"> <array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string> <string>IBNSLayoutConstraint</string>
<string>NSButton</string>
<string>NSButtonCell</string>
<string>NSCustomObject</string> <string>NSCustomObject</string>
<string>NSCustomView</string> <string>NSCustomView</string>
<string>NSProgressIndicator</string> <string>NSProgressIndicator</string>
@ -56,6 +58,35 @@
<reference key="NSNextResponder" ref="258451033"/> <reference key="NSNextResponder" ref="258451033"/>
<int key="NSvFlags">268</int> <int key="NSvFlags">268</int>
<array class="NSMutableArray" key="NSSubviews"> <array class="NSMutableArray" key="NSSubviews">
<object class="NSButton" id="657577321">
<reference key="NSNextResponder" ref="1072816887"/>
<int key="NSvFlags">268</int>
<array class="NSMutableArray" key="NSSubviews"/>
<string key="NSFrame">{{10, 134}, {122, 19}}</string>
<reference key="NSSuperview" ref="1072816887"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="134894493">
<int key="NSCellFlags">-2080374784</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents">Round Rect Button</string>
<object class="NSFont" key="NSSupport">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">12</double>
<int key="NSfFlags">16</int>
</object>
<string key="NSCellIdentifier">_NS:9</string>
<reference key="NSControlView" ref="657577321"/>
<int key="NSButtonFlags">-2038153216</int>
<int key="NSButtonFlags2">164</int>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
<object class="NSTextField" id="642967193"> <object class="NSTextField" id="642967193">
<reference key="NSNextResponder" ref="1072816887"/> <reference key="NSNextResponder" ref="1072816887"/>
<int key="NSvFlags">268</int> <int key="NSvFlags">268</int>
@ -244,7 +275,6 @@
<string key="NSFrame">{{224, 84}, {32, 32}}</string> <string key="NSFrame">{{224, 84}, {32, 32}}</string>
<reference key="NSSuperview" ref="258451033"/> <reference key="NSSuperview" ref="258451033"/>
<reference key="NSWindow"/> <reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:945</string> <string key="NSReuseIdentifierKey">_NS:945</string>
<int key="NSpiFlags">28682</int> <int key="NSpiFlags">28682</int>
<double key="NSMaxValue">100</double> <double key="NSMaxValue">100</double>
@ -321,6 +351,14 @@
</object> </object>
<int key="connectionID">226</int> <int key="connectionID">226</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">reload:</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="657577321"/>
</object>
<int key="connectionID">236</int>
</object>
<object class="IBConnectionRecord"> <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection"> <object class="IBOutletConnection" key="connection">
<string key="label">delegate</string> <string key="label">delegate</string>
@ -535,6 +573,22 @@
<float key="scoringTypeFloat">29</float> <float key="scoringTypeFloat">29</float>
<int key="contentType">3</int> <int key="contentType">3</int>
</object> </object>
<object class="IBNSLayoutConstraint" id="79666172">
<reference key="firstItem" ref="402376051"/>
<int key="firstAttribute">5</int>
<int key="relation">0</int>
<reference key="secondItem" ref="657577321"/>
<int key="secondAttribute">6</int>
<float key="multiplier">1</float>
<object class="IBNSLayoutSymbolicConstant" key="constant">
<double key="value">8</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="1072816887"/>
<int key="scoringType">6</int>
<float key="scoringTypeFloat">24</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="884917592"> <object class="IBNSLayoutConstraint" id="884917592">
<reference key="firstItem" ref="402376051"/> <reference key="firstItem" ref="402376051"/>
<int key="firstAttribute">3</int> <int key="firstAttribute">3</int>
@ -647,10 +701,27 @@
<float key="scoringTypeFloat">29</float> <float key="scoringTypeFloat">29</float>
<int key="contentType">3</int> <int key="contentType">3</int>
</object> </object>
<object class="IBNSLayoutConstraint" id="150496551">
<reference key="firstItem" ref="657577321"/>
<int key="firstAttribute">10</int>
<int key="relation">0</int>
<reference key="secondItem" ref="402376051"/>
<int key="secondAttribute">10</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">0.0</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="1072816887"/>
<int key="scoringType">6</int>
<float key="scoringTypeFloat">24</float>
<int key="contentType">2</int>
</object>
<reference ref="49669222"/> <reference ref="49669222"/>
<reference ref="642967193"/> <reference ref="642967193"/>
<reference ref="139778114"/> <reference ref="139778114"/>
<reference ref="402376051"/> <reference ref="402376051"/>
<reference ref="657577321"/>
</array> </array>
<reference key="parent" ref="258451033"/> <reference key="parent" ref="258451033"/>
</object> </object>
@ -828,6 +899,29 @@
<reference key="object" ref="290707669"/> <reference key="object" ref="290707669"/>
<reference key="parent" ref="139778114"/> <reference key="parent" ref="139778114"/>
</object> </object>
<object class="IBObjectRecord">
<int key="objectID">232</int>
<reference key="object" ref="657577321"/>
<array class="NSMutableArray" key="children">
<reference ref="134894493"/>
</array>
<reference key="parent" ref="1072816887"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">233</int>
<reference key="object" ref="134894493"/>
<reference key="parent" ref="657577321"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">234</int>
<reference key="object" ref="79666172"/>
<reference key="parent" ref="1072816887"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">235</int>
<reference key="object" ref="150496551"/>
<reference key="parent" ref="1072816887"/>
</object>
</array> </array>
</object> </object>
<dictionary class="NSMutableDictionary" key="flattenedProperties"> <dictionary class="NSMutableDictionary" key="flattenedProperties">
@ -835,6 +929,7 @@
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array key="143.IBNSViewMetadataConstraints"> <array key="143.IBNSViewMetadataConstraints">
<reference ref="150496551"/>
<reference ref="865006730"/> <reference ref="865006730"/>
<reference ref="831384658"/> <reference ref="831384658"/>
<reference ref="566883659"/> <reference ref="566883659"/>
@ -842,6 +937,7 @@
<reference ref="310034208"/> <reference ref="310034208"/>
<reference ref="1033518145"/> <reference ref="1033518145"/>
<reference ref="884917592"/> <reference ref="884917592"/>
<reference ref="79666172"/>
<reference ref="63384401"/> <reference ref="63384401"/>
<reference ref="602857839"/> <reference ref="602857839"/>
<reference ref="314583816"/> <reference ref="314583816"/>
@ -913,6 +1009,11 @@
</array> </array>
<string key="23.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="23.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="231.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="231.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="232.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="232.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="233.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="234.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="235.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="96.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/> <boolean value="NO" key="96.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="96.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="96.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary> </dictionary>
@ -920,13 +1021,24 @@
<nil key="activeLocalization"/> <nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/> <dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/> <nil key="sourceID"/>
<int key="maxID">231</int> <int key="maxID">236</int>
</object> </object>
<object class="IBClassDescriber" key="IBDocument.Classes"> <object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions"> <array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription"> <object class="IBPartialClassDescription">
<string key="className">MPPasswordWindowController</string> <string key="className">MPPasswordWindowController</string>
<string key="superclassName">NSWindowController</string> <string key="superclassName">NSWindowController</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">reload:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">reload:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">reload:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<dictionary class="NSMutableDictionary" key="outlets"> <dictionary class="NSMutableDictionary" key="outlets">
<string key="contentContainer">NSView</string> <string key="contentContainer">NSView</string>
<string key="contentField">NSTextField</string> <string key="contentField">NSTextField</string>