Mitchell Simoens
Mitchell Simoens

Reputation: 2536

Electron browser icon not showing in Linux

Using electron 1.2.1 and electron-packager 7.0.3, after building the icon for the BrowserWindow is not showing up for linux (Ubuntu 14.04 x64), it's the ? image. If I don't create the asar file then the icon shows up. If I check to make sure the file exists when I launch the app it says it exists and I can even use the fs module to copy it outside the asar file. So the image is there but it's not being used by electron when within the asar file.

If I have the file outside the asar file and change the path to the BrowserWindow's icon config to match that file, it still doesn't pick up the icon so it's not whether the file is inside the asar file or not, it's if the app is loaded from an asar file.

I'm using a simple example:

var electron      = require('electron'),
    BrowserWindow = electron.BrowserWindow,
    Path          = require('path'),
    fs            = require('fs'),
    icon          = Path.resolve(__dirname, 'resources', 'foo.png');

electron.app.on('ready', function() {
    var win = new BrowserWindow({
        width  : 400,
        height : 400,
        title  : 'Test',
        icon   : icon
    });

    win.loadUrl('file://' + Path.resolve(__dirname, 'foo.html'));

    win.openDevTools();

    //for dev
    console.log(fs.existsSync(icon));  //reports true
});

If I check the existsSync in the console via:

require('fs').existsSync(require('path).resolve(__dirname, 'resources', 'foo.png'));

it says the file exists. foo.png is a PNG 256x256 file. Tried with a 32x32 and 64x64 PNG file but still no luck.

Any ideas on what is going wrong?

Upvotes: 1

Views: 1115

Answers (2)

Chris B.
Chris B.

Reputation: 382

This is probably a bug. Here's a walkaround that helped for me;

setTimeout(() => bw.webContents.openDevTools(), 100)

Upvotes: 0

LuisPinto
LuisPinto

Reputation: 1697

You have to create a .icns file with your image. Here you have a website to convert your png to a incs file

After that save your file on your working directory and the include as you are doing.

With electron-packager there is an icon option so you puth the icon path there, e.g:

electron-packager dashboard Netbeast --platform=linux --arch=all --version=0.37.2 --icon=dashboard/desktop_app/icon.icns 

Upvotes: -1

Related Questions