mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 12:52:21 +00:00
Restructure reopening of Files. Introduced some regression with the welcome screen being shown too often.
This commit is contained in:
@@ -50,8 +50,14 @@
|
||||
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
||||
if(!flag) {
|
||||
[self _loadWelcomeWindow];
|
||||
[self.welcomeWindow orderFront:self];
|
||||
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||
BOOL showWelcomeScreen = YES;
|
||||
if(reopen) {
|
||||
showWelcomeScreen = ![self _reopenLastDocument];
|
||||
}
|
||||
if(showWelcomeScreen) {
|
||||
[self _showWelcomeWindow];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@@ -70,7 +76,7 @@
|
||||
selector:@selector(_applicationDidFinishRestoringWindows:)
|
||||
name:NSApplicationDidFinishRestoringWindowsNotification
|
||||
object:nil];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,38 +87,18 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
||||
serverDaemon = [[MPServerDaemon alloc] init];
|
||||
lockDaemon = [[MPLockDaemon alloc] init];
|
||||
autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
||||
//autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
||||
|
||||
|
||||
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||
BOOL showWelcomeScreen = !_shouldOpenFile;
|
||||
if(reopen && !_restoredWindows && !_shouldOpenFile) {
|
||||
NSDocumentController *documentController = [NSDocumentController sharedDocumentController];
|
||||
NSArray *documents = [documentController documents];
|
||||
if([documents count] > 0) {
|
||||
return; // There's a document open
|
||||
}
|
||||
|
||||
NSArray *recentDocuments = [documentController recentDocumentURLs];
|
||||
NSURL *documentUrl;
|
||||
if([recentDocuments count] > 0) {
|
||||
documentUrl = recentDocuments[0];
|
||||
}
|
||||
else {
|
||||
NSString *lastPath = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyLastDatabasePath];
|
||||
documentUrl = [NSURL URLWithString:lastPath];
|
||||
}
|
||||
if([documentUrl isFileURL]) {
|
||||
[documentController openDocumentWithContentsOfURL:documentUrl display:YES
|
||||
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {}];
|
||||
|
||||
}
|
||||
else {
|
||||
[self _loadWelcomeWindow];
|
||||
[self.welcomeWindow orderFront:self];
|
||||
}
|
||||
showWelcomeScreen = ![self _reopenLastDocument];
|
||||
}
|
||||
if(showWelcomeScreen) {
|
||||
[self _showWelcomeWindow];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +153,11 @@
|
||||
_restoredWindows = [documents count] > 0;
|
||||
}
|
||||
|
||||
- (void)_showWelcomeWindow {
|
||||
[self _loadWelcomeWindow];
|
||||
[self.welcomeWindow makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
- (void)_loadWelcomeWindow {
|
||||
if(!_welcomeWindow) {
|
||||
NSArray *topLevelObject;
|
||||
@@ -175,4 +166,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)_reopenLastDocument {
|
||||
NSDocumentController *documentController = [NSDocumentController sharedDocumentController];
|
||||
NSArray *documents = [documentController documents];
|
||||
if([documents count] > 0) {
|
||||
return YES; // The document is already open
|
||||
}
|
||||
NSArray *recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
|
||||
NSURL *documentUrl = nil;
|
||||
if([recentDocuments count] > 0) {
|
||||
documentUrl = recentDocuments[0];
|
||||
}
|
||||
else {
|
||||
NSString *lastPath = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyLastDatabasePath];
|
||||
documentUrl =[NSURL URLWithString:lastPath];
|
||||
}
|
||||
BOOL isFileURL = [documentUrl isFileURL];
|
||||
if(isFileURL) {
|
||||
[documentController openDocumentWithContentsOfURL:documentUrl
|
||||
display:YES
|
||||
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {}];
|
||||
}
|
||||
return isFileURL;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2528</string>
|
||||
<string>2531</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user