Merge branch 'feature/fix-welcome-window-restoration'

This commit is contained in:
Michael Starke
2019-04-24 15:57:51 +02:00
2 changed files with 41 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -187,7 +187,7 @@
<constraint firstItem="ITj-5P-sn9" firstAttribute="leading" secondItem="9Nv-Zl-Z9p" secondAttribute="leading" constant="20" id="oWL-PJ-VCT"/>
<constraint firstAttribute="bottom" secondItem="ITj-5P-sn9" secondAttribute="bottom" id="syW-TO-uwv"/>
</constraints>
<point key="canvasLocation" x="-378" y="-552"/>
<point key="canvasLocation" x="-680" y="-522"/>
</view>
</objects>
<resources>

View File

@@ -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;
@@ -82,11 +90,22 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
if(self) {
_userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init];
self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
_shouldOpenFile = NO;
self.notificationState = MPAppDelegateDidReceiveNoNotification;
[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;
}
@@ -109,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 */
@@ -154,22 +182,12 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
return [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyOpenEmptyDatabaseOnLaunch];
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
_shouldOpenFile = NO;
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(_applicationDidFinishRestoringWindows:)
name:NSApplicationDidFinishRestoringWindowsNotification
object:nil];
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyQuitOnLastWindowClose];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
[self hideWelcomeWindow];
if([[MPTemporaryFileStorageCenter defaultCenter] hasPendingStorages]) {
dispatch_async(dispatch_get_main_queue(), ^{
[MPTemporaryFileStorageCenter.defaultCenter cleanupStorages];
@@ -201,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,6 +309,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
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) {
@@ -328,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) {
@@ -338,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) {