From e8fa409cef7502e53afd9f1a43599613c5fceba9 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 24 Apr 2019 12:06:16 +0200 Subject: [PATCH 1/3] =?UTF-8?q?moved=20observation=20to=20init=20since=20i?= =?UTF-8?q?t=E2=80=99s=20need=20from=20the=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MacPass/MPAppDelegate.m | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 4062902d..d9d364d9 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -82,11 +82,21 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi if(self) { _userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init]; self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init]; + _shouldOpenFile = NO; + + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(_applicationDidFinishRestoringWindows:) + name:NSApplicationDidFinishRestoringWindowsNotification + object:nil]; + /* We know that we do not use the variable after instantiation */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" MPDocumentController *documentController = [[MPDocumentController alloc] init]; #pragma clang diagnostic pop + + + } return self; } @@ -156,12 +166,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi - (void)applicationWillFinishLaunching:(NSNotification *)notification { - _shouldOpenFile = NO; - [NSNotificationCenter.defaultCenter addObserver:self - selector:@selector(_applicationDidFinishRestoringWindows:) - name:NSApplicationDidFinishRestoringWindowsNotification - object:nil]; - } @@ -170,6 +174,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { + [self hideWelcomeWindow]; if([[MPTemporaryFileStorageCenter defaultCenter] hasPendingStorages]) { dispatch_async(dispatch_get_main_queue(), ^{ [MPTemporaryFileStorageCenter.defaultCenter cleanupStorages]; @@ -285,11 +290,13 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } - (void)showWelcomeWindow { + NSApp.dockTile.badgeLabel = @"WELCOME"; if(!self.welcomeWindow) { self.welcomeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO]; + self.welcomeWindow.restorable = NO; // do not restore the welcome window! self.welcomeWindow.releasedWhenClosed = NO; } if(!self.welcomeWindow.contentViewController) { From 25538dd3bf6c89eb7ee49c2df232f31774cd007e Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 24 Apr 2019 12:06:28 +0200 Subject: [PATCH 2/3] Updated to Xcode 10.2 --- MacPass/Base.lproj/WelcomeView.xib | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MacPass/Base.lproj/WelcomeView.xib b/MacPass/Base.lproj/WelcomeView.xib index 3563c2ea..7c8c7f46 100644 --- a/MacPass/Base.lproj/WelcomeView.xib +++ b/MacPass/Base.lproj/WelcomeView.xib @@ -1,8 +1,8 @@ - + - + @@ -187,7 +187,7 @@ - + From c46dba59c3c6d602456b7668cb77151a0be8cddd Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 24 Apr 2019 15:57:20 +0200 Subject: [PATCH 3/3] do not show welcome window when we are asked to open a file via double-click in the Finder --- MacPass/MPAppDelegate.m | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index d9d364d9..9bad8060 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -51,6 +51,13 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDidChangeStoredKeyFilesSettings"; +typedef NS_OPTIONS(NSInteger, MPAppDelegateNotifcationState) { + MPAppDelegateDidReceiveNoNotification = 0, + MPAppDelegateDidReceiveApplicationDidRestoreWindowsNotification = 1, + MPAppDelegateDidReceiveApplicationDidFinsishLaunchinNotification = 2, + MPAppdelegateDidReceiveAllNotifications = (MPAppDelegateDidReceiveApplicationDidRestoreWindowsNotification | MPAppDelegateDidReceiveApplicationDidFinsishLaunchinNotification) +}; + @interface MPAppDelegate () { @private MPDockTileHelper *_dockTileHelper; @@ -62,6 +69,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi @property (strong) IBOutlet NSWindow *passwordCreatorWindow; @property (strong, nonatomic) MPPreferencesWindowController *preferencesController; @property (strong, nonatomic) MPPasswordCreatorViewController *passwordCreatorController; +@property (assign, nonatomic) MPAppDelegateNotifcationState notificationState; @property (strong) MPEntryContextMenuDelegate *itemActionMenuDelegate; @@ -83,6 +91,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi _userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init]; self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init]; _shouldOpenFile = NO; + self.notificationState = MPAppDelegateDidReceiveNoNotification; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_applicationDidFinishRestoringWindows:) @@ -119,6 +128,15 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } } +- (void)setNotificationState:(MPAppDelegateNotifcationState)notificationState { + if(notificationState != self.notificationState) { + _notificationState = notificationState; + if(MPAppdelegateDidReceiveAllNotifications == (self.notificationState & MPAppdelegateDidReceiveAllNotifications)) { + [self _applicationDidFinishLaunchingAndDidRestoreWindows]; + } + } +} + - (void)awakeFromNib { _isAllowedToStoreKeyFile = NO; /* Update the … at the save menu */ @@ -164,11 +182,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi return [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyOpenEmptyDatabaseOnLaunch]; } - -- (void)applicationWillFinishLaunching:(NSNotification *)notification { - -} - - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyQuitOnLastWindowClose]; } @@ -206,6 +219,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi /* Disable updates if in debug or nosparkle */ [SUUpdater sharedUpdater]; #endif + self.notificationState |= MPAppDelegateDidReceiveApplicationDidFinsishLaunchinNotification; } #pragma mark - @@ -290,7 +304,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } - (void)showWelcomeWindow { - NSApp.dockTile.badgeLabel = @"WELCOME"; if(!self.welcomeWindow) { self.welcomeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable @@ -335,8 +348,12 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi #pragma mark - #pragma mark Private Helper - (void)_applicationDidFinishRestoringWindows:(NSNotification *)notification { + self.notificationState |= MPAppDelegateDidReceiveApplicationDidRestoreWindowsNotification; +} + +- (void)_applicationDidFinishLaunchingAndDidRestoreWindows { NSArray *documents = NSDocumentController.sharedDocumentController.documents; - BOOL restoredWindows = documents.count > 0; + BOOL hasOpenDocuments = documents.count > 0; for(NSDocument *document in documents) { for(NSWindowController *windowController in document.windowControllers) { @@ -345,8 +362,8 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi } BOOL reopen = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch]; - BOOL showWelcomeScreen = !restoredWindows && !_shouldOpenFile; - if(reopen && !restoredWindows && !_shouldOpenFile) { + BOOL showWelcomeScreen = !hasOpenDocuments && !_shouldOpenFile; + if(reopen && !hasOpenDocuments && !_shouldOpenFile) { showWelcomeScreen = ![((MPDocumentController *)NSDocumentController.sharedDocumentController) reopenLastDocument]; } if(showWelcomeScreen) {