javascriptwindows-10electronsystem-tray

electron tray icon issue on windows 10


I have built the electron app and now want to use Tray feature as mentioned here

i am giving icon path which is located in the build folder at the base location as shown below

tray = new Tray(`file://${__dirname}/build/icon.ico`);

But this is throwing the following error enter image description here

I want to know how to use the icon as its not mentioned in the documentation.


Solution

  • this worked for me .Although the size of the icon has to be small to be shown

    const { Tray, nativeImage } = require('electron');
    
    const iconPath = path.join(__dirname, 'build/icon-st.png');
    mainWindow.tray = new Tray(nativeImage.createFromPath(iconPath));