8

I'm having an issue setting the icon for my Electron app in two different ways:

Non-Packaged (Running the app via terminal)

My main.js does specify an 'icon' value, pointing to the icon file, but it does not apply.

Packaged (with electron-packager)

My package.json file specifies the 'icon' key, pointing to the icon file, and I have the .icns (Mac) file in the build directory. I used electron-packager to build the app, but the icon is not applied, the default electron icon is used instead.

Not sure what I'm doing wrong here, everything appears correct.

Karric
  • 1,415
  • 2
  • 19
  • 32
  • Possible duplicate of [How to set app icon for Electron / Atom Shell App](https://stackoverflow.com/questions/31529772/how-to-set-app-icon-for-electron-atom-shell-app) – pushkin May 01 '18 at 15:19

4 Answers4

9

If you mean the icon on the dock, on MAC can should use:

const app = electron.app;
const image = electron.nativeImage.createFromPath(
  app.getAppPath() + "/public/YOUR_APP_IMAGE_NAME"
);
app.dock.setIcon(image);
iharel
  • 242
  • 2
  • 7
2

There is a good tutorial here:

Follow the steps but make sure you don't skip anything.

This is also a relevant issue on GitHub:

More links here:

rsp
  • 107,747
  • 29
  • 201
  • 177
  • 1
    The first link solved my packaged icon issue, it seems the --icon flag is mandatory, despite the icon key value. That tutorial implies but does not directly state that setting the unpackaged icon path in Main.js only works on Ubuntu. Is this true? Unpackaged icon matters more to me, as I'm working on many electron apps at once. – Karric Mar 20 '17 at 12:33
1

If you come across this issue on Mac OS, it may be the icon cache that is messing things up. It was the case for me. I used the following command to clear it :

sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder

Then I built the app again and this time it I had the icon I specified with electron-packager.

Karim Mortabit
  • 692
  • 2
  • 9
  • 19
0

You can add this script to package.json and it works perfectly fine. Mostly its because of the path issues.

"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",