Well, if you check NSWindowDelegate.windowWillMiniaturize:
you'll notice that its parameter is just a notification (its name is NSWindowWillMiniaturizeNotification
).
So, you can simply observe that notification to get notified whenever a window in your app is about to be minimized:
NotificationCenter.default.addObserver(forName: NSWindow.willMiniaturizeNotification, object: nil, queue: nil) { notification in
print("This window is about to be minimized:", notification.object)
}
You can also do the same to get notified about other events like:
NSWindow.didMiniaturizeNotification
: After the window is minimized.
NSWindow.didDeminiaturizeNotification
: After the window is restored/deminimized.
NSWindow.willEnterFullScreenNotification
: Before entering full screen.
NSWindow.didEnterFullScreenNotification
: After entering full screen.
NSWindow.willExitFullScreenNotification
: Before exiting full screen.
NSWindow.didExitFullScreenNotification
: After exiting full screen.
Full list of notifications here.