How to set app icon for Electron / Atom Shell App
Asked Answered
P

15

224

How do you set the app icon for your Electron app?

I am trying BrowserWindow({icon:'path/to/image.png'}); but it does not work.

Do I need to pack the app to see the effect?

Pennoncel answered 21/7, 2015 at 3:20 Comment(2)
You can follow github.com/onmyway133/blog/issues/66Hobnob
One thing you can do for Mac is put a postinstall script in your project that will copy the .icns file in place under node_modules/ automatically.Tlaxcala
G
227

Setting the icon property when creating the BrowserWindow only has an effect on Windows and Linux.

To set the icon on OS X, you can use electron-packager and set the icon using the --icon switch.

It will need to be in .icns format for OS X. There is an online icon converter which can create this file from your .png.

Gustav answered 21/7, 2015 at 11:58 Comment(10)
Can you fix this answer to be accurate wrt Windows please?Bathhouse
Thanks @ShawnRakowski, you're right - I've just tested this and the icon property does indeed work on Windows too. I've updated my answer to reflect this.Gustav
This worked at first, but then I sent the distributable app to my friend and it didnt work! Any ideas?Misuse
I'm not seeing how to do this. I tried electron-package . --all --icon but got an error "TypeError: Path must be a string. Received true"Vernalize
@Vernalize you will need to do something like the following electron-packager . YourApplicationName --all --icon "path/to/my/icon.ico"Dermato
I agree with Tieme. The answer's linked icon converter is old and only supports icon sizes of 256x256, which is ok for Windows and Linux, but Mac OS .icns files max out at 1024x1024. @AlexWarren, please update your answer to reflect this.Outstand
With electron-packager you'll want to do something like "--icon=src/assets/icons/logo" and electron will handle adding the extension for the relevant platformCircumambulate
The solution by @Circumambulate works (I checked the source code and you don't need to specify the extension), but I'm forced to call a touch builddir/myapp.app to see the icon in my Finder. Seems like MacOS need help to see the new icon. See gist.github.com/fabiofl/5873100#gistcomment-1320553Pipsqueak
Have you ever had an issue where the app icon looks fine but the icon that shows up within the notification looks bad, almost like when a TV goes bad...Relent
On Windows, I'm using ` BrowserWindow({icon: './icon.png'}) ` and it works when using ` npm start ` on terminal. When the window pops up, it has the customized tiny icon on top of the window. But the problem is that it only works while testing using ` npm start ` so when I package my app into an ` .exe ` file, The app no longer has the icon in the explorer nor on top of its window when opened.Avocet
A
97

Below is the solution that I have :

new BrowserWindow({
  width: 800,
  height: 600,
  icon: __dirname + '/Bluetooth.ico',
})
Archaic answered 9/4, 2016 at 13:33 Comment(6)
Worth mentioning that __dirname is the path of your /src/ folder (i.e. the folder of your app.js/main.js file).Library
.icns not needed ?Strongminded
how to create .ico file, is there any online tool?Maiocco
@EdisonPebojot search on google "online ico creator" there are plenty of ico creater.Archaic
IntelliJ suggested that is better to write: icon: path.join(__dirname, 'icons/png/256x256.png')Brakesman
this solution seems not working on macOs.Excaudate
E
36

For Electron < 3.0 version. Updated package.json:

"build": {
  "appId": "com.my-website.my-app",
  "productName": "MyApp",
  "copyright": "Copyright © 2019 ${author}",
  "mac": {
    "icon": "./public/icons/mac/icon.icns",     <---------- set Mac Icons
    "category": "public.app-category.utilities"
  },
  "win": {
    "icon": "./public/icons/png/256x256.png" <---------- set Win Icon
  },
  "files": [
    "./build/**/*",
    "./dist/**/*",
    "./node_modules/**/*",
    "./public/**/*",       <---------- need for get access to icons
    "*.js"
  ],
  "directories": {
    "buildResources": "public" <---------- folder where placed icons
  }
},

After build application you can see icons. This solution don't show icons in developer mode. I don't setup icons in new BrowserWindow().

Eserine answered 14/8, 2019 at 12:0 Comment(1)
'build' in the application package.json is not supported since 3.0 anymoreStutter
T
23

**

IMPORTANT: OUTDATED ANSWER, LOOK AT THE OTHER NEWER SOLUTIONS

**

You can do it for macOS, too. Ok, not through code, but with some simple steps:

  1. Find the .icns file you want to use, open it and copy it via Edit menu
  2. Find the electron.app, usually in node_modules/electron/dist
  3. Open the information window
  4. Select the icon on the top left corner (gray border around it)
  5. Paste the icon via cmd+v
  6. Enjoy your icon during development :-)

enter image description here

Actually it is a general thing not specific to electron. You can change the icon of many macOS apps like this.

Taster answered 19/11, 2016 at 8:44 Comment(5)
This is amazing, thank you for this. I did need to drag and drop to get it to work but amazing nonetheless.Mertens
Complete instructions: support.apple.com/kb/PH25383?locale=en_USKv
This seems to only work for development. When I run 'yarn dist', the icns file gets replaced with the default electron one.Essam
@Essam Actually he said 6. Enjoy your icon during *development* :-)Recessional
Well guys... I know... But this fix is over 2 years old... ;-) And btw. you should be able to use this "hack" also on a final build, since you simply change it on the dist app... Have not tried for a while.. And who knows maybe there is an official way, now... ;-)Taster
F
6

If you want to update the app icon in the taskbar, then Update following in main.js (if using typescript then main.ts)

win.setIcon(path.join(__dirname, '/src/assets/logo-small.png'));

__dirname points to the root directory (same directory as package.json) of your application.

Francenefrances answered 14/4, 2019 at 13:30 Comment(2)
sure about mac?Amblyopia
This works for windows but not MacRolon
M
6

In case you're converting an existing web app to an Electron app, you can use the following code:

const path = require('path')

const mainWindow = new BrowserWindow({
  icon: path.join(__dirname, 'favicon.ico'),
})
Malang answered 6/8, 2021 at 6:29 Comment(0)
S
2

In my case, I don't need to specify any path such as ./, since I use build directory, and this is my configuration:

"build": {
  "directories":{
     "output": "build"
  },
  "mac": {
     "icon": "build/logo.icns"
  },
  "win": {
     "icon": "build/logo.png"
   }
}

I found that using ./logo.png will make electron shows the same error:

default Electron icon is used reason=application icon is not set

Schwejda answered 20/1, 2022 at 13:32 Comment(0)
F
2

windows 10

electron-packager

electron-packager . appname--platform=win32 --arch=x64 --overwrite --icon=icons/icon.ico --out=release-builds

the icon keeps getting cached, so using the --out flag helped.

Fusibility answered 12/7, 2022 at 3:22 Comment(0)
N
1

electron-packager


Setting the icon property when creating the BrowserWindow only has an effect on Windows and Linux platforms. you have to package the .icns for max

To set the icon on OS X using electron-packager, set the icon using the --icon switch.

It will need to be in .icns format for OS X. There is an online icon converter which can create this file from your .png.

electron-builder


As a most recent solution, I found an alternative of using --icon switch. Here is what you can do.
  1. Create a directory named build in your project directory and put the .icns the icon in the directory as named icon.icns.
  2. run builder by executing command electron-builder --dir.

You will find your application icon will be automatically picked up from that directory location and used for an application while packaging.

Note: The given answer is for recent version of electron-builder and tested with electron-builder v21.2.0

Nolitta answered 2/9, 2019 at 4:37 Comment(0)
F
1
win = new BrowserWindow({width: 1000, height: 1000,icon: __dirname + '/logo.png'}); //*.png or *.ico will also work 

in my case it worked !

Fronnia answered 18/12, 2020 at 6:20 Comment(0)
A
0

Please be aware that the examples for icon file path tend to assume that main.js is under the base directory. If the file is not in the base directory of the app, the path specification must account for that fact.

For example, if the main.js is under the src/ subdirectory, and the icon is under assets/icons/, this icon path specification will work:

icon: __dirname + "../assets/icons/icon.png"
Algetic answered 16/5, 2019 at 20:59 Comment(0)
P
0

In Linux, you can search icon.png in the project directory and change both files(one for Debian and one for Redhat) with your custom icon(with the same name).

Pearlypearman answered 10/3, 2022 at 6:23 Comment(0)
A
0

If you are using electron-builder, you can follow their documentation on how to add your app-icon.

You can specify a path to set the icon in the electron-builder.json5 configuration file, e.g. for mac:

/**
 * @see https://www.electron.build/configuration/configuration
 */
{
appId: 'YourAppId',
mac: {
  artifactName: '${productName}_${version}.${ext}',
  target: ['dmg'],
  icon: 'public/logo.png',
 },
}
Amphichroic answered 9/1, 2023 at 1:15 Comment(0)
P
0

It is recommended to use .ico extension for app icon. You can refer the piece of code which is mentioned below. If suppose you having any other image formats, Just convert it with .ico extension using online converters

let mainWindow;
mainWindow = new BrowserWindow({
        width:1200,
        height:600,
        icon: path.join(__dirname,'/icon.ico'),
    });
  • Here _dirname refers to your file path.
  • icon.ico - Image file
Piggott answered 24/7, 2023 at 0:40 Comment(0)
B
-5

For windows use Resource Hacker

Download and Install: :D

http://www.angusj.com/resourcehacker/

  • Run It
  • Select open and select exe file
  • On your left open a folder called Icon Group
  • Right click 1: 1033
  • Click replace icon
  • Select the icon of your choice
  • Then select replace icon
  • Save then close

You should have build the app

Barvick answered 12/10, 2020 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.