SystemTrayIconComponent and dark/light menu bar

What is the suggested method to handle OS X dark mode with JUCE and the SystemTrayIconComponent? With the dark mode enabled, system menu bar icons usually become white instead of black (since most OS X icons are monochrome).

Some googling seems to suggest that you need to provide a templated image, but I guess this is not supported via JUCE? So perhaps an easier solution would be to expose a method in the SystemTrayIconComponent class to detect the current mode, and subscribe to changes of it?

More info here: http://stackoverflow.com/questions/25379525/how-to-detect-dark-mode-in-yosemite-to-change-the-status-bar-menu-icon 

Sounds like something we could add, though TBH I'd never even heard of dark mode!

Perhaps a help method in the Desktop class could be a good start?

 

bool Desktop::getOsXDarkModeIsActive()

{

    NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];

    return [osxMode isEqualToString:@"Dark"];

}

 

Yep, that sounds like a good approach..

I’ve just run in to this issue.

I see getOsXDarkModeIsActive() has been added but it looks like the recommended approach is to use the NSImage setTemplate to make this automatic:

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];

NSImage *image = [NSImage imageNamed:@“statusItemIcon”];

[image setTemplate:YES];

[statusItem setImage:image];

I’m not quite sure how to get this working with the custom view currently used. I also see custom views shouldn’t be set on NSStatusItem according to the associated header comments.

1 Like