2

I have an Electron app and I'm working on a Mac to make a Windows installer for it.

Right now I have an /installers directory and a setupEvents.js file that handles all of the Squirrel events. Most of it is from the Windows installer documentation:

import { app } from 'electron';
module.exports = {
  handleSquirrelEvent: function() {
    if (process.argv.length === 1) {
      return false;
    }

    const ChildProcess = require('child_process');
    const path = require('path');

    const appFolder = path.resolve(process.execPath, '..');
    const rootAtomFolder = path.resolve(appFolder, '..');
    const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
    const exeName = path.basename(process.execPath);
    const spawn = function(command, args) {
      let spawnedProcess, error;

      try {
        spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
      } catch (error) {}

      return spawnedProcess;
    };

    const spawnUpdate = function(args) {
      return spawn(updateDotExe, args);
    };

    const squirrelEvent = process.argv[1];
    switch (squirrelEvent) {
      case '--squirrel-install':
        case '--squirrel-updated':
        // Optionally do things such as:
        // - Add your .exe to the PATH
        // - Write to the registry for things like file associations and
        // explorer context menus

        // Install desktop and start menu shortcuts
        spawnUpdate(['--createShortcut', exeName]);

      setTimeout(app.quit, 1000);
      return true;

      case '--squirrel-uninstall':
        // Undo anything you did in the --squirrel-install and
        // --squirrel-updated handlers

        // Remove desktop and start menu shortcuts
        spawnUpdate(['--removeShortcut', exeName]);

      setTimeout(app.quit, 1000);
      return true;

      case '--squirrel-obsolete':
        // This is called on the outgoing version of your app before
        // we update to the new version - it's the opposite of
        // --squirrel-updated

        app.quit();
      return true;
    }
  }
}

So far, this works as expected, except the shortcut icon that is added to the desktop has the title "Electron", and I'm not sure how to change that. My package.json has a name and productName in it:

{
  "name": "my app",
  "description": "my app description",
  "productName": "my app",
  "appCopyright": "me",
  "appCategoryType": "Productivity",
...

And my installer config looks like this:

{
    appDirectory: path.join(outPath, 'myapp-win32-ia32/'),
    authors: 'me',
    noMsi: true,
    outputDirectory: path.join(outPath, 'windows-installer'),
    exe: 'myapp.exe',
    setupExe: 'myappInstaller.exe',
    setupIcon: path.join(rootPath, 'assets', 'win', 'icon.ico'),
    skipUpdateIcon: true
  }

I'm not sure where to tell the installer that the shortcut icon should have my app's name instead of just "Electron".

Thanks in advance!

Cassidy
  • 3,328
  • 5
  • 39
  • 76

1 Answers1

2

I finally figured it out.

In your project.json file, the command you use to build your application is where the code will go.

The part you're looking for is --version-string.ProductName=\"My App Name\" and is found in "scripts": { "build": "YOUR CODE HERE"}:

Side note... I'm using electron-packager.

Here's an example using my code:
"pack:win64": "electron-packager ./ --overwrite --asar=true --platform=win32 --arch=x64 --ignore=assets --ignore=build --ignore=installers --icon=./images/icons/icon.ico --prune=true --out=build/win --version-string.ProductName=\"My App Name\""

Pixel Rubble
  • 1,104
  • 3
  • 14
  • 26
  • Do you happen to know how this can be accomplished for a plain-vanilla WPF app that doesn't use `project.json`? – InteXX Jul 18 '20 at 22:28