How can I detect if my SwiftUI Window has been closed?

My macOS SwiftUI app has a single Window scene. .onAppear() is called when it is created, but if it is closed, .onDisappear() is not called.

How can I detect when the window is closed? Note, I need to distinguish between closed and inactive or background.

scenePhase is not updated for the window or any of its subviews when the window is deactivated. controlPhase is, however.

Note that my app delegate implements:

	func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
		return false
	}
How can I detect if my SwiftUI Window has been closed?
 
 
Q