NSWindow 3 buttons are still gray after hide and unhide+activate

spend X hours on this. test *** combinations.
I have mac OS app without storyboard.
I also have menu status bar.
I click on the manu status bar to hide/unhide my app.

- (void) menuBarControllerStatusChanged: (BOOL) active {

     if([[NSApplication sharedApplication] isHidden])
     {
        NSImage *image = [UIImage imageNamed:@"newsFeedsAlertOFF"];
        self.mainStatusBar.image = image;
    
        NSAssert(self.windowController!=nil, @"window controll is nil");
        NSAssert(self.windowController.window!=nil, @"window  is nil");

        [[NSApplication sharedApplication] unhide:self];
        [self.windowController.window makeKeyAndOrderFront:self];
        [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];

     }
     else
     {

        [NSApplication sharedApplication] hide:self];
        [[NSApplication sharedApplication] deactivate];

     }
}



The problem :
on unhide, the app is visible and active (focused) BUT the NSWindow 3 button are gray color.
ONLY if I active another app (safari for example) and return to my app, then the NSWindow 3 buttons are display with color.
In what situation the NSWindow is active and the 3 buttons are gray ? If there is no "normal" situation, maybe I need to report bug ?
attention 1 : I don't use storyboard. everthing is created by code (EXCEPT the MainMenu.xib)

attention 2 : this was tested on Mojave and Catalina .
attention3 : the 3 buttons are flickering for 0.1 seconds with their color and then turn gray.(with this sample code, but not in all code combinations I tested)
Thanks in adavnce.

Answered by ec100 in 401063022

Found the problem :

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
  return YES;
}

when I disable this,
I could hide/unhide the my app and activate it correctly with 3 buttons of window with their colors.
Another thing import was :

[self.windowController.window orderOut:nil];

I wish AppKit and xcode were more developer friendly.

so please If someone is going to help, give a TESTED direction.

Yelling orders when asking for help is not the fairest practice. 😁


everthing is created by code

And you should first show more code, you probably have an error somewhere. How do you want anyone to guess ?

Accepted Answer

Found the problem :

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
  return YES;
}

when I disable this,
I could hide/unhide the my app and activate it correctly with 3 buttons of window with their colors.
Another thing import was :

[self.windowController.window orderOut:nil];

I wish AppKit and xcode were more developer friendly.

Thanks for the feedback.


A lesson here is that you should post more code when you ask question.

We spend time investigating on parts that were not relevant.

Shoudl you have shown this at first, it would have been immediately visible.


One could also say that your post was not very much forum friendly.😉


Have a good day anyhow.

NSWindow 3 buttons are still gray after hide and unhide+activate
 
 
Q