manish kumar
manish kumar

Reputation: 4700

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.

Upvotes: 5

Views: 12314

Answers (5)

Ari G
Ari G

Reputation: 177

I worked around the issue by converting a png to base64, and used nativeImage.createFromDataURL to render accordingly

Upvotes: 1

NIrav Modi
NIrav Modi

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

Abi Taneja
Abi Taneja

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

manish kumar
manish kumar

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

John Woodruff
John Woodruff

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

Related Questions