Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to set menubar icon colour on macOS...? #317

Open
jamiebullock opened this issue Jan 22, 2021 · 4 comments
Open

Any way to set menubar icon colour on macOS...? #317

jamiebullock opened this issue Jan 22, 2021 · 4 comments

Comments

@jamiebullock
Copy link

On macOS, if we use a black-on-transparent PNG for the the menubar icon then in dark mode we get a white icon and in light mode we get a black icon.

Is there any way to explicitly set the colour of the icon so it is always a fixed colour? I tried just changing the colour in the PNG, but it still comes out black or white.

@joeflateau
Copy link

@jamiebullock you can create light and dark variations and use https://www.electronjs.org/docs/api/native-theme to decide between them. Make sure you do NOT include "Template" in the new file names or they will be treated as templates

@dotdotdev
Copy link

@joeflateau Can you please show an example/code?

@joeflateau
Copy link

@dotdotdev no, I do not. But you'd be wiring nativeTheme's updated event and nativeTheme.shouldUseDarkColors to
the Tray#setImage method

@davidpaulsson
Copy link

davidpaulsson commented Feb 18, 2022

@dotdotdev something like this should work. import nativeTheme from electron, then

function getTrayIcon(isDark = nativeTheme.shouldUseDarkColors) {
	// some logic to determine what icon to use
	return path.join(__dirname, `assets/icon${isDark ? '-dark' : ''}.png`);
}

const mb = menubar({
	icon: getTrayIcon(),
	... your options
});

mb.on('ready', () => {
	nativeTheme.on('updated', () => mb.tray.setImage(getTrayIcon()));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants