From 2371793da41614ff85e9e31219aa455bd835ec77 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 11 Aug 2014 15:46:32 +0200 Subject: [PATCH] Autotype fix dialog now only shows candiates. --- MacPass/Base.lproj/GroupInspectorView.xib | 5 +- MacPass/MPAutotypeHelper.h | 12 +--- MacPass/MPAutotypeHelper.m | 19 ++--- MacPass/MPDocument+Autotype.h | 25 +++++++ MacPass/MPDocument+Autotype.m | 42 +++++++++++ MacPass/MPDocument.h | 1 + MacPass/MPDocument.m | 4 ++ MacPass/MPEntryViewController.m | 38 +++++----- MacPass/MPFixAutotypeWindowController.m | 17 +++-- MacPass/MPGroupInspectorViewController.h | 1 + MacPass/MPGroupInspectorViewController.m | 20 +++--- MacPass/MPSettingsHelper.h | 14 ++-- MacPass/MPSettingsHelper.m | 85 ++++++++++++++--------- 13 files changed, 178 insertions(+), 105 deletions(-) diff --git a/MacPass/Base.lproj/GroupInspectorView.xib b/MacPass/Base.lproj/GroupInspectorView.xib index fc2e90df..bfb220eb 100644 --- a/MacPass/Base.lproj/GroupInspectorView.xib +++ b/MacPass/Base.lproj/GroupInspectorView.xib @@ -1,13 +1,14 @@ - + - + + diff --git a/MacPass/MPAutotypeHelper.h b/MacPass/MPAutotypeHelper.h index 540266fa..5d73acd4 100644 --- a/MacPass/MPAutotypeHelper.h +++ b/MacPass/MPAutotypeHelper.h @@ -8,16 +8,10 @@ #import +@class MPDocument; + @interface MPAutotypeHelper : NSObject -/** - * Tests the given item for a possible wrong autotype format - * MacPass 0.4 and 0.4.1 did store wrong Autotype sequences and thus mangled database files - * - * @param item Item to test for malformation. Allowed Items are KPKNode, KPKEntry, KPKGroup and KPKAutotype - * - * @return YES if the given item is considered a possible candiate. NO in all other cases - */ -+ (BOOL)isCandidateForMalformedAutotype:(id)item; + @end diff --git a/MacPass/MPAutotypeHelper.m b/MacPass/MPAutotypeHelper.m index e5dcb53f..4c900a50 100644 --- a/MacPass/MPAutotypeHelper.m +++ b/MacPass/MPAutotypeHelper.m @@ -8,6 +8,9 @@ #import "MPAutotypeHelper.h" +#import "MPDocument.h" + +#import "KPKTree.h" #import "KPKGroup.h" #import "KPKEntry.h" @@ -16,20 +19,6 @@ @implementation MPAutotypeHelper -+ (BOOL)isCandidateForMalformedAutotype:(id)item { - - NSString *keystrokeSequence; - if([item isKindOfClass:[KPKEntry class]] && ![((KPKEntry *)item).autotype hasDefaultKeystrokeSequence]) { - keystrokeSequence = ((KPKEntry *)item).autotype.defaultKeystrokeSequence; - } - else if( [item isKindOfClass:[KPKGroup class]] && ![item hasDefaultAutotypeSequence]) { - keystrokeSequence = ((KPKGroup *)item).defaultAutoTypeSequence; - } - else if( [item isKindOfClass:[KPKWindowAssociation class]] && ![item hasDefaultKeystrokeSequence]){ - keystrokeSequence = ((KPKWindowAssociation *)item).keystrokeSequence; - } - /* if nothing is true, keystrokeSequence is nil an hence return is NO */ - return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]); -} + @end diff --git a/MacPass/MPDocument+Autotype.h b/MacPass/MPDocument+Autotype.h index fe29ebf5..a552d4c3 100644 --- a/MacPass/MPDocument+Autotype.h +++ b/MacPass/MPDocument+Autotype.h @@ -24,6 +24,31 @@ @interface MPDocument (Autotype) +/** + * Tests the given item for a possible wrong autotype format + * MacPass 0.4 and 0.4.1 did store wrong Autotype sequences and thus mangled database files + * + * @param item Item to test for malformation. Allowed Items are KPKNode, KPKEntry, KPKGroup and KPKAutotype + * + * @return YES if the given item is considered a possible candiate. NO in all other cases + */ ++ (BOOL)isCandidateForMalformedAutotype:(id)item; + +/** + * Returns an NSArray containing all Autotype Contexts that match the given window title + * + * @param windowTitle Window title to search matches for + * + * @return NSArray of MPAutotypeContexts for the given window title + */ - (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle; +/** + * Checks if the document has malformed autotype items + * + * @return YES if any malformed items are found + */ +- (BOOL)hasMalformedAutotypeItems; + +- (NSArray *)malformedAutotypeItems; @end diff --git a/MacPass/MPDocument+Autotype.m b/MacPass/MPDocument+Autotype.m index 482f878c..c7765ba2 100644 --- a/MacPass/MPDocument+Autotype.m +++ b/MacPass/MPDocument+Autotype.m @@ -22,6 +22,7 @@ #import "MPDocument+Autotype.h" #import "MPAutotypeContext.h" +#import "MPAutotypeHelper.h" #import "KPKGroup.h" #import "KPKEntry.h" @@ -30,6 +31,22 @@ @implementation MPDocument (Autotype) ++ (BOOL)isCandidateForMalformedAutotype:(id)item { + + NSString *keystrokeSequence; + if([item isKindOfClass:[KPKEntry class]] && ![((KPKEntry *)item).autotype hasDefaultKeystrokeSequence]) { + keystrokeSequence = ((KPKEntry *)item).autotype.defaultKeystrokeSequence; + } + else if( [item isKindOfClass:[KPKGroup class]] && ![item hasDefaultAutotypeSequence]) { + keystrokeSequence = ((KPKGroup *)item).defaultAutoTypeSequence; + } + else if( [item isKindOfClass:[KPKWindowAssociation class]] && ![item hasDefaultKeystrokeSequence]){ + keystrokeSequence = ((KPKWindowAssociation *)item).keystrokeSequence; + } + /* if nothing is true, keystrokeSequence is nil an hence return is NO */ + return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]); +} + - (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle { if(!windowTitle) { return nil; @@ -59,4 +76,29 @@ return contexts; } +- (BOOL)hasMalformedAutotypeItems { + return [[self malformedAutotypeItems] count] > 0; +} + +- (NSArray *)malformedAutotypeItems { + NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:1000]; + [self _flattenGroup:self.root toArray:items]; + NSPredicate *malformedPrediacte = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + return [MPDocument isCandidateForMalformedAutotype:evaluatedObject]; + }]; + NSArray *malformedItems = [items filteredArrayUsingPredicate:malformedPrediacte]; + return malformedItems; +} + +- (void)_flattenGroup:(KPKGroup *)group toArray:(NSMutableArray *)array { + [array addObject:group]; + for(KPKEntry *entry in group.entries) { + [array addObject:entry]; + [array addObjectsFromArray:entry.autotype.associations]; + } + for(KPKGroup *childGroup in group.groups) { + [self _flattenGroup:childGroup toArray:array]; + } +} + @end diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index e96731ae..3df594f8 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -65,6 +65,7 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) { @interface MPDocument : NSDocument @property (nonatomic, readonly, assign) BOOL encrypted; +@property (nonatomic, readonly, assign) NSUInteger unlockCount; // Amount of times the Document was unlocked; @property (strong, readonly, nonatomic) KPKTree *tree; @property (nonatomic, weak, readonly) KPKGroup *root; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index e67bda36..50e36495 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -64,6 +64,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey NSData *_encryptedData; } +@property (nonatomic, assign) NSUInteger unlockCount; + @property (strong, nonatomic) MPSavePanelAccessoryViewController *savePanelViewController; @property (strong, nonatomic) KPKTree *tree; @@ -120,6 +122,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey _readOnly = NO; _activeFlags = MPEntrySearchTitles; _hasSearch = NO; + _unlockCount = 0; self.tree = [KPKTree templateTree]; self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds]; } @@ -285,6 +288,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey self.compositeKey = nil; // clear the key? } if(isUnlocked) { + self.unlockCount += 1; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidUnlockDatabaseNotification object:self]; } return isUnlocked; diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 6de43848..d5e41e04 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -9,9 +9,12 @@ #import "MPEntryViewController.h" #import "MPAppDelegate.h" #import "MPOutlineViewController.h" + #import "MPDocument.h" #import "MPDocument+Search.h" +#import "MPDocument+Autotype.h" #import "MPDocumentWindowController.h" + #import "MPPasteBoardController.h" #import "MPOverlayWindowController.h" #import "MPContextBarViewController.h" @@ -66,7 +69,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; @interface MPEntryViewController () { MPEntryContextMenuDelegate *_menuDelegate; BOOL _isDisplayingContextBar; - BOOL _showFooterInfo; + BOOL _didUnlock; } @property (strong) NSArrayController *entryArrayController; @@ -191,9 +194,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [self _setupHeaderMenu]; [parentColumn setHidden:YES]; - - [self.footerInfoText setHidden:!_showFooterInfo]; - [self.footerInfoText setStringValue:NSLocalizedString(@"DOCUMENT_AUTOTYPE_CORRUPTION_WARNING", "")]; } - (NSResponder *)reconmendedFirstResponder { @@ -225,24 +225,11 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; selector:@selector(_didUpdateSearchResults:) name:MPDocumentDidChangeSearchResults object:document]; - + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didUnlockDatabase:) + name:MPDocumentDidUnlockDatabaseNotification + object:document]; [self.contextBarViewController registerNotificationsForDocument:document]; - - /* Setup warning message at the bottom*/ - NSArray *array = [[NSUserDefaults standardUserDefaults] arrayForKey:kMPSettingsKeyDocumentsAutotypeFixNoteWasShown]; - NSString *path = [[document fileURL] path]; - if(!path) { - return; // No path, nothing to do - } - if(![array containsObject:path]) { - array = array ? [array arrayByAddingObject:path] : @[path]; - [[NSUserDefaults standardUserDefaults] setObject:array forKey:kMPSettingsKeyDocumentsAutotypeFixNoteWasShown]; - [[NSUserDefaults standardUserDefaults] synchronize]; - _showFooterInfo = YES; - } - else { - _showFooterInfo = NO; - } } #pragma mark NSTableViewDelgate @@ -405,6 +392,15 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [self _showContextBar]; } +- (void)_didUnlockDatabase:(NSNotification *)notificiation { + MPDocument *document = [[self windowController] document]; + /* If the document was locked and unlocked we do not need to recheck */ + if(document.unlockCount != 1) { + [self.footerInfoText setHidden:![document hasMalformedAutotypeItems]]; + [self.footerInfoText setStringValue:NSLocalizedString(@"DOCUMENT_AUTOTYPE_CORRUPTION_WARNING", "")]; + } +} + #pragma mark ContextBar - (void)_updateContextBar { MPDocument *document = [[self windowController] document]; diff --git a/MacPass/MPFixAutotypeWindowController.m b/MacPass/MPFixAutotypeWindowController.m index 4c66903a..9710c327 100644 --- a/MacPass/MPFixAutotypeWindowController.m +++ b/MacPass/MPFixAutotypeWindowController.m @@ -7,14 +7,17 @@ // #import "MPFixAutotypeWindowController.h" + #import "MPDocument.h" +#import "MPDocument+Autotype.h" +#import "MPIconHelper.h" + #import "KPKNode.h" #import "KPKEntry.h" #import "KPKGroup.h" #import "KPKAutotype.h" #import "KPKWindowAssociation.h" -#import "MPIconHelper.h" NSString *const kMPAutotypeCell = @"AutotypeCell"; NSString *const kMPTitleCell = @"TitleCell"; @@ -31,7 +34,7 @@ NSString *const kMPIconCell = @"IconCell"; @end @interface MPFixAutotypeWindowController () { - NSMutableArray *_elements; + NSArray *_itemsCache; BOOL _didRegisterForUndoRedo; } @end @@ -66,7 +69,7 @@ NSString *const kMPIconCell = @"IconCell"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidUndoChangeNotification object:manager]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeDocument:) name:NSUndoManagerDidCloseUndoGroupNotification object:manager]; } - _elements = nil; + _itemsCache = nil; [self.tableView reloadData]; } @@ -201,11 +204,10 @@ NSString *const kMPIconCell = @"IconCell"; #pragma mark Data accessors - (NSArray *)entriesAndGroups { - if(nil == _elements) { - _elements = [[NSMutableArray alloc] init]; - [self flattenGroup:self.workingDocument.root toArray:_elements]; + if(nil == _itemsCache) { + _itemsCache = [self.workingDocument malformedAutotypeItems]; } - return _elements; + return _itemsCache; } @@ -222,6 +224,7 @@ NSString *const kMPIconCell = @"IconCell"; #pragma mark NSUndoManagerNotifications - (void)_didChangeDocument:(NSNotification *)notification { + _itemsCache = nil; [self.tableView reloadData]; } diff --git a/MacPass/MPGroupInspectorViewController.h b/MacPass/MPGroupInspectorViewController.h index 67fa0ff7..669fbec3 100644 --- a/MacPass/MPGroupInspectorViewController.h +++ b/MacPass/MPGroupInspectorViewController.h @@ -20,6 +20,7 @@ @property (weak) IBOutlet NSPopUpButton *searchPopupButton; @property (weak) IBOutlet NSPopUpButton *autotypePopupButton; +@property (weak) IBOutlet HNHRoundedTextField *autotypeSequenceTextField; - (void)setupBindings:(MPDocument *)document; diff --git a/MacPass/MPGroupInspectorViewController.m b/MacPass/MPGroupInspectorViewController.m index 826e84cc..e07eca2e 100644 --- a/MacPass/MPGroupInspectorViewController.m +++ b/MacPass/MPGroupInspectorViewController.m @@ -66,7 +66,7 @@ } - (void)setupBindings:(MPDocument *)document { - [self bind:@"group" toObject:document withKeyPath:@"selectedGroup" options:nil]; + [self bind:NSStringFromSelector(@selector(group)) toObject:document withKeyPath:NSStringFromSelector(@selector(selectedGroup)) options:nil]; } - (void)setGroup:(KPKGroup *)group { @@ -80,16 +80,11 @@ if(self.group) { [self.titleTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(name)) options:nil]; [self.expiresCheckButton bind:NSValueBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil]; - [self.expiresCheckButton bind:NSTitleBinding - toObject:self.group.timeInfo - withKeyPath:NSStringFromSelector(@selector(expiryTime)) - options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; - [self.expireDateSelectButton bind:NSHiddenBinding - toObject:self.group.timeInfo - withKeyPath:NSStringFromSelector(@selector(expires)) - options:@{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }]; - [self.autotypePopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:@"isAutoTypeEnabled" options:nil]; - [self.searchPopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:@"isSearchEnabled" options:nil]; + [self.expiresCheckButton bind:NSTitleBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expiryTime)) options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; + [self.expireDateSelectButton bind:NSHiddenBinding toObject:self.group.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:@{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }]; + [self.autotypePopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(isAutoTypeEnabled)) options:nil]; + [self.autotypeSequenceTextField bind:NSValueBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(defaultAutoTypeSequence)) options:nil]; + [self.searchPopupButton bind:NSSelectedTagBinding toObject:self.group withKeyPath:NSStringFromSelector(@selector(isSearchEnabled)) options:nil]; } else { [self.titleTextField unbind:NSValueBinding]; @@ -98,8 +93,9 @@ [self.expiresCheckButton unbind:NSTitleBinding]; [self.expiresCheckButton setTitle:NSLocalizedString(@"EXPIRES", "")]; [self.expireDateSelectButton unbind:NSHiddenBinding]; - [self.autotypePopupButton unbind:NSSelectedTagBinding]; [self.searchPopupButton unbind:NSSelectedTagBinding]; + [self.autotypePopupButton unbind:NSSelectedTagBinding]; + [self.autotypeSequenceTextField unbind:NSValueBinding]; } } diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index 0c68db09..f90e0272 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -42,15 +42,15 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideNotes; APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideURL; /* Document/Key Location store */ -APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath; -APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases; -APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases; +APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath; // Path to the last opened Database. Workaround if users have disabled the feautere in the OS +APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases; // NSDictionary of all db file urls and the corresponding key file url +APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases; // YES if key files should be rememberd /* Autotype */ -APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey; // Should MacPass swap control for command. This is usefull in a cross plattform environment -APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; // Is Global Autotype enabled? -APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key -APPKIT_EXTERN NSString *const kMPSettingsKeyDocumentsAutotypeFixNoteWasShown; // +APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey; // Should MacPass swap control for command. This is usefull in a cross plattform environment +APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; // Is Global Autotype enabled? +APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key +APPKIT_EXTERN NSString *const kMPDepricatedSettingsKeyDocumentsAutotypeFixNoteWasShown; // YES if Autotype fix was shown /* Search */ APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 0e4a48be..8c3c5081 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -30,13 +30,12 @@ NSString *const kMPSettingsKeyLegacyHideNotes = @"Legacy NSString *const kMPSettingsKeyLegacyHideURL = @"LegacyHideURL"; NSString *const kMPSettingsKeyLastDatabasePath = @"LastDatabasePath"; -NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases"; NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesForDatabases"; +NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases"; NSString *const kMPSettingsKeySendCommandForControlKey = @"SendCommandKeyForControlKey"; NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAutotype"; NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey = @"GlobalAutotypeKeyDataKey"; -NSString *const kMPSettingsKeyDocumentsAutotypeFixNoteWasShown = @"DocumentsAutotypeFixNoteWasShown"; NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilterMode"; @@ -50,6 +49,11 @@ NSString *const kMPSettingsKeyPasswordCharacterFlags = @"Passwo NSString *const kMPSettingsKeyPasswordUseCustomString = @"PasswordUseCustomString"; NSString *const kMPSettingsKeyPasswordCustomString = @"PasswordCustomString"; +/* Depricated */ +NSString *const kMPDepricatedSettingsKeyRememberKeyFilesForDatabases = @"kMPSettingsKeyRememberKeyFilesForDatabases"; +NSString *const kMPDepricatedSettingsKeyLastDatabasePath = @"MPLastDatabasePath"; +NSString *const kMPDepricatedSettingsKeyDocumentsAutotypeFixNoteWasShown = @"DocumentsAutotypeFixNoteWasShown"; + @implementation MPSettingsHelper + (void)setupDefaults { @@ -66,40 +70,57 @@ NSString *const kMPSettingsKeyPasswordCustomString = @"Passwo } + (NSDictionary *)_standardDefaults { - return @{ - kMPSettingsKeyShowInspector: @YES, // Show the Inspector by default - kMPSettingsKeyPasteboardClearTimeout: @30, // 30 seconds - kMPSettingsKeyClearPasteboardOnQuit: @YES, - kMPSettingsKeyDoubleClickURLToLaunch: @NO, - kMPSettingsKeyOpenEmptyDatabaseOnLaunch: @NO, - kMPSettingsKeyReopenLastDatabaseOnLaunch: @YES, - kMPSettingsKeyHttpPort: @19455, - kMPSettingsKeyEnableHttpServer: @NO, - kMPSettingsKeyShowMenuItem: @YES, - kMPSettingsKeyLockOnSleep: @YES, - kMPSettingsKeyIdleLockTimeOut: @0, // 5 minutes - kMPSettingsKeyLegacyHideNotes: @NO, - kMPSettingsKeyLegacyHidePassword: @YES, - kMPSettingsKeyLegacyHideTitle: @NO, - kMPSettingsKeyLegacyHideURL: @NO, - kMPSettingsKeyLegacyHideUsername: @NO, - kMPSettingsKeyRememberKeyFilesForDatabases: @NO, - kMPSettingsKeySendCommandForControlKey: @YES, - kMPSettingsKeyEntrySearchFilterMode: @0, - kMPSettingsKeyEnableGlobalAutotype: @NO, - kMPSettingsKeyEnableQuicklookPreview: @NO, - kMPSettingsKeyCopyGeneratedPasswordToClipboard: @NO, - kMPSettingsKeyDefaultPasswordRounds: @50000, - kMPSettingsKeyDefaultPasswordLength: @12, - kMPSettingsKeyPasswordCharacterFlags: @(MPPasswordCharactersAll), - kMPSettingsKeyPasswordUseCustomString: @NO, - kMPSettingsKeyPasswordCustomString: @"" - }; + static NSDictionary *standardDefaults; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + standardDefaults = @{ + kMPSettingsKeyShowInspector: @YES, // Show the Inspector by default + kMPSettingsKeyPasteboardClearTimeout: @30, // 30 seconds + kMPSettingsKeyClearPasteboardOnQuit: @YES, + kMPSettingsKeyDoubleClickURLToLaunch: @NO, + kMPSettingsKeyOpenEmptyDatabaseOnLaunch: @NO, + kMPSettingsKeyReopenLastDatabaseOnLaunch: @YES, + kMPSettingsKeyHttpPort: @19455, + kMPSettingsKeyEnableHttpServer: @NO, + kMPSettingsKeyShowMenuItem: @YES, + kMPSettingsKeyLockOnSleep: @YES, + kMPSettingsKeyIdleLockTimeOut: @0, // 5 minutes + kMPSettingsKeyLegacyHideNotes: @NO, + kMPSettingsKeyLegacyHidePassword: @YES, + kMPSettingsKeyLegacyHideTitle: @NO, + kMPSettingsKeyLegacyHideURL: @NO, + kMPSettingsKeyLegacyHideUsername: @NO, + kMPSettingsKeyRememberKeyFilesForDatabases: @NO, + kMPSettingsKeySendCommandForControlKey: @YES, + kMPSettingsKeyEntrySearchFilterMode: @0, + kMPSettingsKeyEnableGlobalAutotype: @NO, + kMPSettingsKeyEnableQuicklookPreview: @NO, + kMPSettingsKeyCopyGeneratedPasswordToClipboard: @NO, + kMPSettingsKeyDefaultPasswordRounds: @50000, + kMPSettingsKeyDefaultPasswordLength: @12, + kMPSettingsKeyPasswordCharacterFlags: @(MPPasswordCharactersAll), + kMPSettingsKeyPasswordUseCustomString: @NO, + kMPSettingsKeyPasswordCustomString: @"" + }; + }); + return standardDefaults; } ++ (NSArray *)_depircatedSettingsKeys { + static NSArray *depircatedSettings; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + depircatedSettings = @[ kMPDepricatedSettingsKeyRememberKeyFilesForDatabases, + kMPDepricatedSettingsKeyLastDatabasePath, + kMPDepricatedSettingsKeyDocumentsAutotypeFixNoteWasShown ]; + }); + return depircatedSettings; +} + + + (void)_removeObsolteValues { /* Clear old style values */ - for(NSString *key in @[ @"kMPSettingsKeyRememberKeyFilesForDatabases", @"MPLastDatabasePath" ]) { + for(NSString *key in [self _depircatedSettingsKeys]) { [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; } }