Status item icon and dark mode

I worte a Status item app and designed an icon for it, a black symbol with a transparent background.
Now the Finder menu and status item uses also black symbols (Big Sur), but on my MacBook (Catalina) I have white symbols and text, so my icon doesn’t show properly.
How can I change it, depending on ‘IsDarkMode’ (can’t assign app.icon = othericon), or shouldn’t this be necessary and handled by dark mode itself?

If you use a PDF based symbol, the system can do it for you an swap coloring.

See NSImageMBS class and isTemplate.

No, it’s a .png

In my past projects PNG has worked as well. Construct the NSImageMBS with a picture and set isTemplate true.

1 Like

Well, thanks, but who to assign your recommendations to the icon of the app exactly?
Screenshot 2020-11-09 at 18.54.25

For some guidance on how to do this, take a look at the MBS Example Project in /MacCocoa/NSStatusItem/StatusItem with PDF Icon

You can just set isTemplate to true for both ways.
It should be use your picture as a template and then create the light and dark version for you.

Thanks, guys.
Well, this is for a menu item picture or a canvas, but how can I access the icon of the app, the one that appears in the status menu (which is the app icon, no?).
As I showed, app.Icon = myNSMBStemplatePicture does not work.

Dock you mean the Dock icon at the bottom of the screen or the StatusItem at the top of the screen?

It seems to be the same. But I suppress the dock icon, with LSUIElement.

They’re two different things and how you interact with them is different, although to confuse matters it’s perfectly reasonable to include the status item icon in your main application icon, that only shows on the status item (yes Apple added this ability to their ICNS files).

It would appear to me that the problem is how to set the icon of the status item, which depends on how you interact with the status item. AFAIK it’s not supported by Xojo and must be done via a plugin or declares. So how are you creating the Status Item?

var n as new NSImageMBS(Wecker)

’ create stuff
si = new NSStatusItemMBS ’ statusitem
sm = new NSMenuMBS ’ menu

’ status item
call si.CreateMenu
si.ToolTip = “Set an alarm clock”
si.Image = n ’ create status menu pic

’ create menu items

’ attach menu
si.Menu = sm

So to be correct: I use the same picture as an app icon and the status menu symbol.
Now, is
si.isTemplate = true
the solution?

Well, it works… better - for the black & transparent image.
However, sometimes I use colors in the status menu image, and these don’t work anymore (always replaced by black!)
So, any other tip than isTemplate = true??

A new thought: Where from can I get the information, if the Finder menubar (text) color is black or white? Seems not important, if dark mode is in effect or not.
Then I adapt the status item image (white or black with transparent background) accordingly.

Well, any kind of color other than black gets lost that way. Do you have an other (MBS) method, or know how to find out which color the Finder menu / status bar has (system, Gestalt, etc, call?) Thanks.

Screenshot 2020-11-11 at 17.02.33

After switching from dark mode to light mode, my images changes to black (handled in App.AppearanceChanged), but the rest stays white…

Here’s more, it’s not grave, but not nice…

More food for thought:
I found out, it hasn’t so much to do with dark mode, but with the desktop picture brightness. If one uses a bright desktop picture, the Finder und status menu items are black, if it is dark, they are white. Irrespective of dark mode.
Now, I found the ‘thing’ colorgroup in Xojo. Could that be a way to change the status item icon color, and is there a ‘desktop-color-has-changed’-event to update the status item icon color as the Finder does it?

ColorGroups are currently broken on Desktop.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.