2
0

Fixed a bunch of OS X issues.

[FIXED]     Don't create a moc when the main moc is unset.
[FIXED]     Load the MPUserEntity into the moc when doing selectUser:
[FIXED]     Remove KVO on activeUserObjectID, isn't used anymore.  Instead, override setActiveUser:
[FIXED]     Don't show the password window on launch.
[FIXED]     Don't force unlock of the key whenever unset - only when the window pops.
[REMOVED]   Migration - this app is not ready for explicit migration, additionally, this block appears to cause a lock-up of the PSC.
This commit is contained in:
Maarten Billemont
2013-04-23 20:38:56 -04:00
parent 35ef2b0789
commit cb7e145e83
7 changed files with 188 additions and 78 deletions

View File

@@ -30,6 +30,8 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
+ (NSManagedObjectContext *)managedObjectContextForThreadIfReady {
NSManagedObjectContext *mainManagedObjectContext = [[self get] mainManagedObjectContextIfReady];
if (!mainManagedObjectContext)
return nil;
if ([[NSThread currentThread] isMainThread])
return mainManagedObjectContext;

View File

@@ -11,6 +11,12 @@
#import "MPAppDelegate_Store.h"
#import <Carbon/Carbon.h>
@interface MPAppDelegate ()
@property(nonatomic) BOOL wasRunning;
@end
@implementation MPAppDelegate
@synthesize statusItem;
@@ -110,7 +116,12 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
- (void)selectUser:(NSMenuItem *)item {
self.activeUser = (MPUserEntity *)[[MPAppDelegate managedObjectContextForThreadIfReady] objectRegisteredForID:[item representedObject]];
NSError *error = nil;
NSManagedObjectContext *moc = [MPAppDelegate managedObjectContextForThreadIfReady];
self.activeUser = (MPUserEntity *)[moc existingObjectWithID:[item representedObject] error:&error];
if (error)
err(@"While looking up selected user: %@", error);
}
- (void)showMenu {
@@ -170,7 +181,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
#pragma mark - NSApplicationDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Setup delegates and listeners.
[MPConfig get].delegate = self;
__weak id weakSelf = self;
@@ -188,18 +199,6 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
self.statusItem.target = self;
self.statusItem.action = @selector(showMenu);
__weak MPAppDelegate *wSelf = self;
[self addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) {
MPUserEntity *activeUser = [wSelf activeUserForThread];
[[[wSelf.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([[obj representedObject] isEqual:[activeUser objectID]])
[obj setState:NSOnState];
else
[obj setState:NSOffState];
}];
[MPMacConfig get].usedUserName = activeUser.name;
} forKeyPath:@"activeUserObjectID" options:0 context:nil];
[[NSNotificationCenter defaultCenter] addObserverForName:UbiquityManagedStoreDidChangeNotification object:nil queue:nil usingBlock:
^(NSNotification *note) {
[self updateUsers];
@@ -232,6 +231,20 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
err(@"Error registering 'lock' hotkey: %d", status);
}
- (void)setActiveUser:(MPUserEntity *)activeUser {
[super setActiveUser:activeUser];
[[[self.usersItem submenu] itemArray] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([[obj representedObject] isEqual:[activeUser objectID]])
[obj setState:NSOnState];
else
[obj setState:NSOffState];
}];
[MPMacConfig get].usedUserName = activeUser.name;
}
- (void)updateMenuItems {
MPUserEntity *activeUser = [self activeUserForThread];
@@ -298,7 +311,15 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[self.passwordWindow showWindow:self];
// Don't show window if we weren't already running (ie. if we haven't been activated before).
if (!self.wasRunning) {
dbg(@"Wasn't running yet, not activating.");
self.wasRunning = YES;
}
else {
dbg(@"Was running already, activating.");
[self.passwordWindow showWindow:self];
}
}
- (void)applicationWillResignActive:(NSNotification *)notification {

View File

@@ -32,21 +32,16 @@
[[MPAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) {
[self.userLabel setStringValue:PearlString( @"%@'s password for:", [[MPAppDelegate get] activeUserForThread].name )];
} forKeyPath:@"activeUser" options:NSKeyValueObservingOptionInitial context:nil];
[[MPAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) {
if (![MPAppDelegate get].key) {
[self unlock];
return;
}
[MPAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
if (![MPAlgorithmDefault migrateUser:[[MPAppDelegate get] activeUserForThread]])
[NSAlert alertWithMessageText:@"Migration Needed" defaultButton:@"OK" alternateButton:nil otherButton:nil
informativeTextWithFormat:@"Certain sites require explicit migration to get updated to the latest version of the "
@"Master Password algorithm. For these sites, a migration button will appear. Migrating these sites will cause "
@"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];
// [[MPAppDelegate get] addObserverBlock:^(NSString *keyPath, id object, NSDictionary *change, void *context) {
// [MPAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
// if (![MPAlgorithmDefault migrateUser:[[MPAppDelegate get] activeUserInContext:moc]])
// [NSAlert alertWithMessageText:@"Migration Needed" defaultButton:@"OK" alternateButton:nil otherButton:nil
// informativeTextWithFormat:@"Certain sites require explicit migration to get updated to the latest version of the "
// @"Master Password algorithm. For these sites, a migration button will appear. Migrating these sites will cause "
// @"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];
[[NSNotificationCenter defaultCenter]
addObserverForName:NSWindowDidBecomeKeyNotification object:self.window queue:nil usingBlock:^(NSNotification *note) {
if (!self.inProgress)

View File

@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1080</int>
<string key="IBDocument.SystemVersion">12C60</string>
<string key="IBDocument.InterfaceBuilderVersion">2840</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<string key="IBDocument.SystemVersion">12D78</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.37</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">2840</string>
<string key="NS.object.0">3084</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string>
@@ -61,6 +61,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{131, 163}, {219, 17}}</string>
<reference key="NSSuperview" ref="1072816887"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="402376051"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -101,6 +102,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{17, 20}, {446, 17}}</string>
<reference key="NSSuperview" ref="1072816887"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="104294954"/>
<string key="NSReuseIdentifierKey">_NS:1505</string>
<bool key="NSEnabled">YES</bool>
@@ -129,6 +131,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{140, 133}, {200, 22}}</string>
<reference key="NSSuperview" ref="1072816887"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="139778114"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -159,8 +162,9 @@
<object class="NSTextField" id="139778114">
<reference key="NSNextResponder" ref="1072816887"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{17, 61}, {446, 64}}</string>
<string key="NSFrame">{{17, 45}, {446, 80}}</string>
<reference key="NSSuperview" ref="1072816887"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="49669222"/>
<object class="NSShadow" key="NSViewShadow">
<double key="NSShadowHoriz">1</double>
@@ -179,7 +183,7 @@
<int key="NSCellFlags2">138412032</int>
<string key="NSContents">S3cretP4s$w0rD</string>
<object class="NSFont" key="NSSupport">
<string key="NSName">Exo-Black</string>
<string key="NSName">SourceCodePro-Black</string>
<double key="NSSize">48</double>
<int key="NSfFlags">16</int>
</object>
@@ -197,6 +201,7 @@
</array>
<string key="NSFrameSize">{480, 200}</string>
<reference key="NSSuperview" ref="258451033"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="642967193"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSClassName">NSView</string>
@@ -206,7 +211,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{224, 84}, {32, 32}}</string>
<reference key="NSSuperview" ref="258451033"/>
<reference key="NSNextKeyView"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:945</string>
<int key="NSpiFlags">28682</int>
<double key="NSMaxValue">100</double>
@@ -214,11 +219,12 @@
</array>
<string key="NSFrameSize">{480, 200}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1072816887"/>
<bool key="NSViewIsLayerTreeHost">YES</bool>
<string key="NSReuseIdentifierKey">_NS:21</string>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSScreenRect">{{0, 0}, {1920, 1058}}</string>
<string key="NSMinSize">{480, 150}</string>
<string key="NSMaxSize">{480, 336}</string>
<bool key="NSWindowIsRestorable">YES</bool>
@@ -496,38 +502,6 @@
<float key="scoringTypeFloat">29</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="310034208">
<reference key="firstItem" ref="642967193"/>
<int key="firstAttribute">9</int>
<int key="relation">0</int>
<reference key="secondItem" ref="402376051"/>
<int key="secondAttribute">9</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>
<object class="IBNSLayoutConstraint" id="645313537">
<reference key="firstItem" ref="642967193"/>
<int key="firstAttribute">3</int>
<int key="relation">0</int>
<reference key="secondItem" ref="1072816887"/>
<int key="secondAttribute">3</int>
<float key="multiplier">1</float>
<object class="IBNSLayoutSymbolicConstant" key="constant">
<double key="value">20</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="1072816887"/>
<int key="scoringType">8</int>
<float key="scoringTypeFloat">29</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="884917592">
<reference key="firstItem" ref="402376051"/>
<int key="firstAttribute">3</int>
@@ -560,6 +534,38 @@
<float key="scoringTypeFloat">24</float>
<int key="contentType">2</int>
</object>
<object class="IBNSLayoutConstraint" id="310034208">
<reference key="firstItem" ref="642967193"/>
<int key="firstAttribute">9</int>
<int key="relation">0</int>
<reference key="secondItem" ref="402376051"/>
<int key="secondAttribute">9</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>
<object class="IBNSLayoutConstraint" id="645313537">
<reference key="firstItem" ref="642967193"/>
<int key="firstAttribute">3</int>
<int key="relation">0</int>
<reference key="secondItem" ref="1072816887"/>
<int key="secondAttribute">3</int>
<float key="multiplier">1</float>
<object class="IBNSLayoutSymbolicConstant" key="constant">
<double key="value">20</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="1072816887"/>
<int key="scoringType">8</int>
<float key="scoringTypeFloat">29</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="566883659">
<reference key="firstItem" ref="139778114"/>
<int key="firstAttribute">3</int>
@@ -640,6 +646,22 @@
<reference key="object" ref="139778114"/>
<array class="NSMutableArray" key="children">
<reference ref="678134424"/>
<object class="IBNSLayoutConstraint" id="164389612">
<reference key="firstItem" ref="139778114"/>
<int key="firstAttribute">8</int>
<int key="relation">0</int>
<nil key="secondItem"/>
<int key="secondAttribute">0</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">80</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="139778114"/>
<int key="scoringType">3</int>
<float key="scoringTypeFloat">9</float>
<int key="contentType">1</int>
</object>
</array>
<reference key="parent" ref="1072816887"/>
</object>
@@ -768,20 +790,25 @@
<reference key="object" ref="1033518145"/>
<reference key="parent" ref="1072816887"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">231</int>
<reference key="object" ref="164389612"/>
<reference key="parent" ref="139778114"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array class="NSMutableArray" key="143.IBNSViewMetadataConstraints">
<array key="143.IBNSViewMetadataConstraints">
<reference ref="865006730"/>
<reference ref="831384658"/>
<reference ref="566883659"/>
<reference ref="1033518145"/>
<reference ref="884917592"/>
<reference ref="645313537"/>
<reference ref="310034208"/>
<reference ref="1033518145"/>
<reference ref="884917592"/>
<reference ref="63384401"/>
<reference ref="602857839"/>
<reference ref="314583816"/>
@@ -792,6 +819,9 @@
<string key="147.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="148.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="150.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array key="181.IBNSViewMetadataConstraints">
<reference ref="164389612"/>
</array>
<boolean value="NO" key="181.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="181.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<real value="1" key="181.IBViewIntegration.shadowBlurRadius"/>
@@ -841,6 +871,7 @@
<reference ref="671970801"/>
</array>
<string key="23.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="231.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="96.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="96.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
@@ -848,9 +879,62 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">230</int>
<int key="maxID">231</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">MPPasswordWindowController</string>
<string key="superclassName">NSWindowController</string>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="contentContainer">NSView</string>
<string key="contentField">NSTextField</string>
<string key="progressView">NSProgressIndicator</string>
<string key="siteField">NSTextField</string>
<string key="tipField">NSTextField</string>
<string key="userLabel">NSTextField</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="contentContainer">
<string key="name">contentContainer</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo" key="contentField">
<string key="name">contentField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="progressView">
<string key="name">progressView</string>
<string key="candidateClassName">NSProgressIndicator</string>
</object>
<object class="IBToOneOutletInfo" key="siteField">
<string key="name">siteField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="tipField">
<string key="name">tipField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="userLabel">
<string key="name">userLabel</string>
<string key="candidateClassName">NSTextField</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/MPPasswordWindowController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSLayoutConstraint</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/NSLayoutConstraint.h</string>
</object>
</object>
</array>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>

View File

@@ -57,6 +57,12 @@
ReferencedContainer = "container:MasterPassword-iOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.coredata.ubiquity.logLevel 3"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>