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?
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?
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.
electron-package . --all --icon
but got an error "TypeError: Path must be a string. Received true" –
Vernalize electron-packager . YourApplicationName --all --icon "path/to/my/icon.ico"
–
Dermato 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-1320553 –
Pipsqueak Below is the solution that I have :
new BrowserWindow({
width: 800,
height: 600,
icon: __dirname + '/Bluetooth.ico',
})
.icns
not needed ? –
Strongminded icon: path.join(__dirname, 'icons/png/256x256.png')
–
Brakesman 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()
.
**
**
You can do it for macOS, too. Ok, not through code, but with some simple steps:
Actually it is a general thing not specific to electron. You can change the icon of many macOS apps like this.
6. Enjoy your icon during *development* :-)
–
Recessional 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.
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'),
})
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
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.
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.
--icon
switch. Here is what you can do.
build
in your project directory and put the .icns
the icon in the directory as named icon.icns
.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
win = new BrowserWindow({width: 1000, height: 1000,icon: __dirname + '/logo.png'}); //*.png or *.ico will also work
in my case it worked !
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"
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).
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',
},
}
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'),
});
For windows use Resource Hacker
Download and Install: :D
http://www.angusj.com/resourcehacker/
You should have build the app
© 2022 - 2024 — McMap. All rights reserved.
postinstall
script in your project that will copy the .icns file in place under node_modules/ automatically. – Tlaxcala