angularelectronelectron-builderelectron-packager

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>


Solution

  • 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