I have the following code:
+ (BOOL)activateWindow:(NSWindow*)window
{
if (NSApp.activationPolicy != NSApplicationActivationPolicyRegular)
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
if (window)
{
[NSApp activate];
//if (window.isMiniaturized) [window deminiaturize:nil];
[window makeKeyAndOrderFront:nil];
}
return YES;
}
+ (BOOL)hideWindowFromDock:(NSWindow*)window
{
if (NSApp.activationPolicy != NSApplicationActivationPolicyProhibited)
[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
window.isVisible = NO;
return YES;
}
I hide app main window by setting NSApplicationActivationPolicyProhibited if it is minimized or being closed.
The code worked most of the time. But since upgrading to Sonoma, sometimes it won't correctly activate main window. The window icon reappears in the dock, but the window won't show up. I have to click on the window icon again to let it 'order front'.
Sometimes, I observe a very weird behavior of the window being activated. It 'order front' and then disappears and re-appears.