@@ -15,6 +15,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
1515 /// Using strong reference to prevent deallocation when window is hidden.
1616 private var mainWindow : NSWindow ?
1717
18+ /// Tracks when the app is quitting so we can allow window closures.
19+ private var isTerminating = false
20+
1821 func applicationDidFinishLaunching( _: Notification ) {
1922 DiagnosticsLogger . app. info ( " AppDelegate: applicationDidFinishLaunching " )
2023 // Set up notification center delegate to show notifications in foreground
@@ -46,6 +49,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
4649 DiagnosticsLogger . player. info ( " Application will terminate - saved queue for persistence " )
4750 }
4851
52+ func applicationShouldTerminate( _: NSApplication ) -> NSApplication . TerminateReply {
53+ self . isTerminating = true
54+ return . terminateNow
55+ }
56+
4957 /// Registers for system sleep and wake notifications to handle playback appropriately.
5058 private func registerForSleepWakeNotifications( ) {
5159 let notificationCenter = NSWorkspace . shared. notificationCenter
@@ -250,7 +258,7 @@ extension AppDelegate: NSWindowDelegate {
250258 /// In UI test mode, close normally to avoid process conflicts.
251259 func windowShouldClose( _ sender: NSWindow ) -> Bool {
252260 // In UI test mode, allow normal close behavior
253- if UITestConfig . isUITestMode {
261+ if UITestConfig . isUITestMode || self . isTerminating {
254262 return true
255263 }
256264
0 commit comments