Allow never opening window + terminate on last window, with guards

Previously we disabled this combo in f6ba7dd40b because when
implemented naively, it causes an issue where just opening an About
MacVim or Settings window could immediately cause MacVim to exit
(because macOS determined that there were no non-auxillary window open).
This was awkward and potentially made it hard to change the setting
back, and exact behavior depended on OS behavior.

However, it seems like there are legit use case for this combo of
settings. Change it so that we allow setting both of them again, but add
checks so that `applicationShouldTerminateAfterLastWindowClosed:` will
only return `YES` if we have opened at least one Vim window before. This
gives the user a chance to open a window first, so using Settings etc
wouldn't immediately terminate the app.

Fix #1338
This commit is contained in:
Yee Cheng Chin
2022-11-04 18:47:18 -07:00
parent 094418700e
commit cabb4957fa
2 changed files with 13 additions and 0 deletions
+2
View File
@@ -49,6 +49,8 @@
int numChildProcesses;
NSMutableDictionary *inputQueues;
int processingFlag;
BOOL hasShownWindowBefore;
#if !DISABLE_SPARKLE
#if USE_SPARKLE_1
+11
View File
@@ -548,6 +548,15 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
if (!hasShownWindowBefore) {
// If we have not opened a window before, never return YES. This can
// happen when MacVim is not configured to open window at launch. We
// want to give the user a chance to open a window first. Otherwise
// just opening the About MacVim or Settings windows could immediately
// terminate the app (since those are not proper app windows),
// depending if the OS feels like invoking this method.
return NO;
}
return (MMTerminateWhenLastWindowClosed ==
[[NSUserDefaults standardUserDefaults]
integerForKey:MMLastWindowClosedBehaviorKey]);
@@ -888,6 +897,8 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
[NSApp activateIgnoringOtherApps:YES];
shouldActivateWhenNextWindowOpens = NO;
}
hasShownWindowBefore = YES;
}
- (void)setMainMenu:(NSMenu *)mainMenu