0
votes

I'm developing MacOS apps, and every time I click on my application's close button, the window closes, but there's the application icon in DOCK. I've found that many applications that close the window will reopen if they click the icon in the Dock, or activate a window. Could you tell me how to achieve this?

Thank you very much for everything you've done for us, thank you.

1

1 Answers

0
votes

The corresponding method has been found, in fact, no more complex. I chose a simpler method. First of all, I need to define a global variable so that I can find it again So, I define

Var mainWindowController: NSWindowController?

And I've assigned it in the applicationDidFinishLaunching method. Then there is the implementation of the applicationShouldHandleReopen method, which is only a piece of code that can be implemented

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool
{
    if !flag {
        for window in sender.windows {
            window.makeKeyAndOrderFront(self);
        }
    }
    return true
}

Thank you very much for the help of the two friends in the front, thank you