Set icon for Task in Jump List (Windows)

1.3k Views Asked by At

I am trying to set up a icon in the Tasks section of the Jump List for my Electron app. I already successfully set up a icon in the task bar. But I also want to set up my icon in the Tasks section of the Jump List. How can I do that?

I already tried to use the app.setUserTask() method and tried to set up a icon in my JSON file. The icon in the task bar and the icon in the its self is working. I also tried using .ico and .png.

The description and the title are working so I guess that I am doing something wrong with the path or something similar. The ico and png image are in the same directory as my main.js (for Electron).

app.setUserTasks([
    {
      program: process.execPath,
      arguments: '--new-window',
      iconPath: path.join(__dirname,"icon.ico").execPath,
      iconIndex: 1,
      title: 'myApp',
      description: 'myApp'
    }
  ])
2

There are 2 best solutions below

0
snwflk On

First of all, it looks like you mixed up two things in your iconPath. According to the Electron docs, you can use process.execPath to refer to the application executable or use any other absolute path. Since path.join returns a string, it won't have the execPath property. Secondly, I changed the iconIndex to 0.

The following was tested on Windows 7 and Electron 4.1.4:

It appears that PNG files do not work at all – you'll need to use ICO files for the Jump List. Furthermore, the icon cannot be taken from the asar. This means you need an ICO directly in the filesystem and you need to provide an absolute path to it.

Complete code sample:

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

let my_path

my_path = "C:\\icon.png"                                // doesn't work
my_path = "C:\\icon.ico"                                // works
my_path = process.execPath                              // works (uses application icon)
my_path = path.join(__dirname, "icon.png")              // doesn't work, translates to C:\path\to\app\resources\app.asar\icon.png
my_path = path.join(__dirname, "icon.ico")              // doesn't work, translates to C:\path\to\app\resources\app.asar\icon.ico
my_path = path.join(app.getAppPath(), "icon.ico")       // doesn't work, translates to C:\path\to\app\resources\app.asar\icon.ico
my_path = path.join(__dirname, "..", "..", "icon.ico")  // works if icon.ico is in the same directory
                                                        // as the exe "packaged" by electron-packager, assuming icon.ico is copied in


if (os.platform() == "win32") {
    app.setUserTasks([{
        program: process.execPath,
        arguments: '--new-window',
        iconPath: my_path,
        iconIndex: 0,
        title: 'My App',
        description: 'Description of myApp'
    }])
}

let mainWindow

app.on('ready', () => {
    mainWindow = new BrowserWindow()

    mainWindow.on('closed', () => {
        mainWindow = null
        app.quit()
    })
})

Here, doesn't work means a default icon is shown by Windows. I made sure that icon.png and icon.ico were in the app.asar.

1
just4you On

I got it working. icon is changed in the taskmanager, taskbar and the app its self I used this topic

I made sure that the .exe and my img are in same folder. All of my icons are now changed except from the .exe its self.