Set Icon on Electron js Window

Certainly! Here's an example code snippet that demonstrates how to set the icon for an Electron.js window:


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

    app.on('ready', () => {
        const win = new BrowserWindow({
            width: 800,
            height: 600,
            icon: path.join(__dirname, 'icon.png') // Specify the path to your icon file
        });

        // Load your application content
        win.loadURL('https://example.com');
    });

  • In this code, we create a new `BrowserWindow` instance and pass an `icon` option when configuring the window. The `icon` option specifies the path to the icon file you want to use for the window. In this example, we use the `path.join` function to construct the full path to the `icon.png` file located in the same directory as the script.
  • Make sure to replace `'icon.png'` with the actual filename and extension of your icon file. Additionally, ensure that the icon file exists in the correct location.
  • When you run your Electron application with this code, the window will use the specified icon. The icon will be displayed in the window's title bar, taskbar, and other relevant areas of the operating system's user interface.

No comments:

Post a Comment