Puzzling Window Menu problem

My app was rejected from the App Store because it quits when the last window is closed. This behavior is intentional because my app isn't a document-based app. 16 of Apple's own bundled Mac apps that follow a similar design pattern also exhibit this behavior. Nevertheless, I'm preparing a contingency plan in the unlikely case that App Review rejects my appeal.

I have a code branch which modifies my app's behavior to stay open when the window is closed. I restore the window if the user switches back to the app, and also have a menu item under the Window menu (mapped to ⌘0, just like Mail and Calendar) to restore the window.

My question is: Calendar, for example, has a specific entry in the Window menu (Window > Calendar) for restoring the window if you close it. This entry is always present and displayed with a checkmark when the window is open and unminimized. When I try to do this in my app, I have duplicated entries: one entry that I specified in Interface Builder, and one entry that's managed by the system. How do you think Apple is managing their menu item in Calendar?
Answered by RickyRomero in 620886022
I found a solution: After adding the menu option to the Window menu, tell the window to not manage its own Window menu entry by setting window.isExcludedFromWindowsMenu to true. Managing the checked state on this item can be done through the windowDidBecomeKey(_:) and windowDidResignKey(_:) methods on the NSWindowDelegate.

Also, if its window is closed, Calendar brings its own window back if you click on the Dock icon or double-click the app in the Finder. You can mimic this behavior by adding a applicationShouldHandleReopen(_:hasVisibleWindows:) handler to your NSApplicationDelegate.
Accepted Answer
I found a solution: After adding the menu option to the Window menu, tell the window to not manage its own Window menu entry by setting window.isExcludedFromWindowsMenu to true. Managing the checked state on this item can be done through the windowDidBecomeKey(_:) and windowDidResignKey(_:) methods on the NSWindowDelegate.

Also, if its window is closed, Calendar brings its own window back if you click on the Dock icon or double-click the app in the Finder. You can mimic this behavior by adding a applicationShouldHandleReopen(_:hasVisibleWindows:) handler to your NSApplicationDelegate.
Puzzling Window Menu problem
 
 
Q