#How to set MenuBar icon [SOLVED]

1 messages · Page 1 of 1 (latest)

supple sundial
#

I have never touched electron until last night, making a menubar only app, followed the docs etc. and I just cant get it to show any icon in my menubar, the app does launch and I can click it to see my menu, it just doesnt have an icon

import { app, Menu, Tray, nativeImage } from 'electron';
import { platform } from 'node:process';
import path from 'path';

let tray: Tray;

app.whenReady().then(() => {
    const iconPath = path.resolve(__dirname, 'Icon.png');
    console.log(iconPath) // correct path
    const icon = nativeImage.createFromPath(iconPath);

    tray = new Tray(icon);

    const contextMenu = Menu.buildFromTemplate([
        { label: 'hi', type: 'normal', click: () => console.log('hi clicked') },
        { type: 'separator' },
        { label: 'Quit', role: 'quit' },
    ]);

    tray.setContextMenu(contextMenu);

    if (platform === 'darwin') {
        app.dock.hide();
    }
});
supple sundial
#

How to set MenuBar icon [SOLVED]

safe rover
#

Can you please share how you fixed it?

#

I didn't even know that we can set an icon in the menu!!

supple sundial