Reputation: 4700
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.
Upvotes: 5
Views: 12314
Reputation: 177
I worked around the issue by converting a png to base64, and used nativeImage.createFromDataURL to render accordingly
Upvotes: 1
Reputation: 6992
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;
}
}
}
Upvotes: 0
Reputation: 41
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.
Upvotes: 0
Reputation: 4700
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));
Upvotes: 15
Reputation: 1666
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.
Upvotes: 1