Electron — Can't get custom icon to appear
Solution 1
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);
Solution 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:
Solution 3
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
.
Karric
Updated on June 04, 2022Comments
-
Karric almost 2 years
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.