I\'m surprised this doesn\'t happen automatically, but I would like my applications window to open automatically when the Dock icon is clicked.
Just to clarify, when
As others pointed, using applicationShouldHandleReopen method for reopening closed windows in non-document apps is the right way. The only change I want to add is a more flexible way to check what window must be re-displayed, by iterating through the NSApplication's list of visible and invisible .windows and checking for the required window.
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if flag == false {
for window in sender.windows {
if (window.delegate?.isKind(of: WelcomeWindowController.self)) == true {
window.makeKeyAndOrderFront(self)
}
}
}
return true
}
Appendix
a) If window was hidden then it will be showed automatically when user will click on app's Dock icon, so no need to implement applicationShouldHandleReopen method.
b) Checked "Release when closed" option doesn't affect in any way the above behaviour.