macos: don't block shutdown/restart on confirmation

This commit is contained in:
Mitchell Hashimoto
2023-05-19 08:27:19 -07:00
parent 97d9157d22
commit 472958fd12

View File

@ -124,10 +124,29 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
if (windows.isEmpty) { return .terminateNow }
// This probably isn't fully safe. The isEmpty check above is aspirational, it doesn't
// quit work with SwiftUI because windows are retained on close. So instead we check
// quite work with SwiftUI because windows are retained on close. So instead we check
// if there are any that are visible. I'm guessing this breaks under certain scenarios.
if (windows.allSatisfy { !$0.isVisible }) { return .terminateNow }
// If the user is shutting down, restarting, or logging out, we don't confirm quit.
if let event = NSAppleEventManager.shared().currentAppleEvent {
if let why = event.attributeDescriptor(forKeyword: AEKeyword("why?")!) {
switch (why.typeCodeValue) {
case kAEShutDown:
fallthrough
case kAERestart:
fallthrough
case kAEReallyLogOut:
return .terminateNow
default:
break
}
}
}
// We have some visible window, and all our windows will watch the confirmQuit.
confirmQuit = true
return .terminateLater