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
I want to know how to use the icon as its not mentioned in the documentation.
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
I want to know how to use the icon as its not mentioned in the documentation.
Share Improve this question edited Feb 12, 2018 at 7:04 Barr J 10.9k2 gold badges30 silver badges48 bronze badges asked Feb 12, 2018 at 5:55 manish kumarmanish kumar 4,6924 gold badges39 silver badges52 bronze badges5 Answers
Reset to default 15this 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));
Looks like a path issue with Windows. I would recommend using an absolute path using node's path
module to correctly resolve the absolute path, like so:
const iconPath = path.join(__dirname, 'build/icon.ico');
tray = new Tray(iconPath);
There are several excellent comments on this electron issue that give various options for you.
I worked around the issue by converting a png to base64, and used nativeImage.createFromDataURL to render accordingly
Although the build is generated, but the icon isn't visible.
I had the same issue, a icon was not visible on windows 10 tray.
it happened because icon was not not visible in window's image viewer (damaged/corrupted icon).
I've downloaded a colored icon and retried and it worked.
I have created method like below
function getAppPathToExecuteCommand() {
if (process.env.NODE_ENV === "development") {
return app.getAppPath();
}
else {
if (platform.windows) {
return path.dirname(app.getPath("exe"));
} else if (platform.linux) {
return process.resourcesPath;
}
}
}