Handling Squirrel Event in Electron Application

These days I'm going with Electron to create a small native Windows application, and I use the Grunt Electron Installer to create an installer for my application.

The installer was created successfully, but I don’t know how ho handles Squirrel events inside my application, as indicated in the documents that I added to the entry point of my application:

var handleStartupEvent = function() {
    if (process.platform !== 'win32') {
        return false;
    }

    var squirrelCommand = process.argv[1];
    switch (squirrelCommand) {
        case '--squirrel-install':
        case '--squirrel-updated':

            // Optionally do things such as:
            //
            // - Install desktop and start menu shortcuts
            // - Add your .exe to the PATH
            // - Write to the registry for things like file associations and
            //   explorer context menus

            // Always quit when done
            app.quit();

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

            // Always quit when done
            app.quit();

            return true;
        case '--squirrel-obsolete':
            // This is called on the outgoing version of your app before
            // we update to the new version - it the opposite of
            // --squirrel-updated
            app.quit();
            return true;
    }
};

if (handleStartupEvent()) {
    return;
}

But I do not know what to do inside this switch statement, for example, to create shortcuts for my application. Actually, I don’t even know if this switch works at all, because when I install (or uninstall) my application, it starts and never shuts down.

Any help is appreciated!

+4
1

Squirrel :

  case '--squirrel-install':
          target = path.basename(process.execPath);
          updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
          var createShortcut = updateDotExe + ' --createShortcut=' + target + ' --shortcut-locations=Desktop,StartMenu' ;
          console.log (createShortcut);
          exec(createShortcut);
          // Always quit when done
          app.quit();
          return true;

case '--squirrel-uninstall':
            // Undo anything you did in the --squirrel-install and
            // --squirrel-updated handlers
            target = path.basename(process.execPath);
            updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
            var createShortcut = updateDotExe + ' --removeShortcut=' + target ;
            console.log (createShortcut);
            exec(createShortcut);
            // Always quit when done
            app.quit();
            return true;
Hide result
+6

All Articles