Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change ElectronJS App default Icon?

I am new to electronjs. I want to convert an angular app to desktop. I could achieve it successfully but the problem is that the app icon is set to default electron and not the icon I provided as follows:

   win = new BrowserWindow({
    width: 600,
    height: 670,
    icon: `${__dirname}/dist/assets/imgs/logo.png`
  })

I changed the icon after building the app using resource hacker but what I need is to change it at build time in the correct way. what am I missing>

like image 255
TheCondorIV Avatar asked Oct 12 '19 06:10

TheCondorIV


People also ask

How to fix electron always shows default app icon?

I get a problem that electron always shows default app icon. I tried using png, NativeImage, different icon sizes but still the problem Go to node_modules -> electron -> dist, right click on Electron, choose View Info icon must be specified with __dirname (we already did) for electron-packager to pick up correct icons

How to get electron-packager to pick up correct icons?

I tried using png, NativeImage, different icon sizes but still the problem Go to node_modules -> electron -> dist, right click on Electron, choose View Info icon must be specified with __dirname (we already did) for electron-packager to pick up correct icons Build a Desktop app with Gridsome and Electron.

How do I add an icon to electron-builder?

The icon should be called icon.png or icon.ico and it should be at least 256x256 in Windows. The icon should be called icons.icns or icon.png at it should be at least 515x512 in macOS. After placing the icon into the build folder, run the following command: electron-builder will look for an icon into the /build folder and replace it with your icon.

How do I use electron-builder with npm?

After placing the icon into the build folder, run the following command: electron-builder will look for an icon into the /build folder and replace it with your icon. The use of npx rather than npm will prevent to install electron-builder as a dependency; it will run the package directly in the terminal.


Video Answer


1 Answers

In main.js, specify icon

win = new BrowserWindow({
 width: 800, 
 height: 600,
 icon: __dirname + '/Icon/Icon.icns'
})

You can also use helper url methods

const path = require('path')
const url = require('url')
const iconUrl = url.format({
 pathname: path.join(__dirname, 'Icon/Icon.icns'),
 protocol: 'file:',
 slashes: true
})

Check this for reference: https://medium.com/fantageek/changing-electron-app-icon-acf26906c5ad

like image 160
Foram Trada Avatar answered Sep 21 '22 17:09

Foram Trada