Unable to Change .exe file Icon in Electron App with Angular

53 Views Asked by At

I'm currently working on an Electron app that incorporates Angular. I've encountered an issue where I can't seem to change the icon of the generated .exe file. I have two icon files, namely 'logo.png' (256x256) and 'logo.ico' (32x32), both located in my 'src/assets' folder.

Despite trying both 'logo.png' and 'logo.ico' as the icon, I haven't been able to change the .exe file's icon, which remains the default Electron icon.

Could someone kindly help me identify what I might be missing or doing incorrectly? I'm eager to successfully set the .exe icon and would greatly appreciate any insights or solutions. Thank you in advance!

Below is the content of my main.js file and script to generate the executable package generating script:

main.js

const path = require("path");
const { app, BrowserWindow } = require("electron");

/** @type {BrowserWindow} */
let appWindow;

/**
 * *Create the main application window.
 */
function createWindow() {
  appWindow = new BrowserWindow({
    show: false,
    width: 1000,
    height: 800,
    frame: false,
    movable: false,
    resizable: false,
    maximizable: false,
    minimizable: false,
    autoHideMenuBar: true,
    icon: path.join(__dirname, "src/assets/logo.png"),
  });

  // Load your Angular app or a default HTML file
  appWindow.loadFile("dist/angular-electron/index.html");

  // When the window is ready to show, maximize and show it
  appWindow.once("ready-to-show", () => {
    appWindow.maximize();
    appWindow.show();
  });

  // Event when the window is closed.
  appWindow.on("closed", function () {
    appWindow = null;
  });
}

/**
 * *Wait for Electron to be ready, then create the main window.
 */
app.whenReady().then(() => {
  // Create the main window
  createWindow();
});

/**
 * *Handle application quitting gracefully
 */
app.on("before-quit", () => {
  // Perform cleanup or save data before quitting
});

/**
 * *Quit when all windows are closed.
 */
app.on("window-all-closed", function () {
  // On macOS specific close process
  if (process.platform !== "darwin") {
    app.quit();
  }
});

/**
 * *Activate the app when it's opened (for macOS).
 */
app.on("activate", function () {
  if (appWindow === null) {
    createWindow();
  }
});

Scripts

"electron": "electron .",
"clean-dist": "rimraf dist",
"clean-packager": "rimraf embolic-tools-win32-x64",
"electron-start": "npm run clean-dist && ng build && electron .",
"package-win": "npm run clean-packager && npx electron-packager ./ embolic-tools --platform=win32 --icon=src/assets/logo.png"
0

There are 0 best solutions below