Electron provides an API, win.setAppDetails(options), that allows us to set the properties of the window taskbar button:

  • appIdString (Optional) – windowApp User Model ID. This parameter must be set, otherwise other options will have no effect.
  • appIconPathString (Optional) – windowRelaunch Icon.
  • appIconIndexInteger (Optional) –appIconPathIcon index in. WhenappIconPathIf no value is specified, ignore it. The default value is0.
  • relaunchCommandString (Optional) – windowRestart command.
  • relaunchDisplayNameString (Optional) – windowRestart the display name.

The way to use it in code is:



Search for setappDetails keyword in Electron source and find it in UI \base\win\shell.cc



In the first call from shellapi SHGetPropertyStoreForWindow get to specify the properties of window handle, Then set the attributes app_id, app_icon_path, relaunch_command, and relaunch_display_names in sequence.

Note:

1. Your_icon_path must point to a real icon file path. Do not point to the path in the electron resource packaging file, because Windows cannot understand the resources used by Electron.

2. Use double quotation marks around your_cmd_string to prevent incorrect command execution due to Spaces.

Running our electron program, we can see that the taskbar icon is no longer the default executable icon, but the one your_icon_path points to.

Right-click on the taskbar icon to see the name specified your_display_name_string, right-click on the name to view properties, a shortcut to the properties information dialog box, and the target bar to see your_cmD_string.