These days I'm toyng around with Electron to build a small native app for Windows and I'm using Grunt Electron Installer to create an installer for my application.
The installer is created successfully but I don't know how ho handle Squirrel's events inside my app, as stated in the docs I've added this to the entry point of my app:
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's the opposite of
// --squirrel-updated
app.quit();
return true;
}
};
if (handleStartupEvent()) {
return;
}
But I don't know what to do inside this switch statement to, for example, 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 get launched and never quits.
Any help is appreciated!
Windows. Squirrel. Windows target is maintained, but deprecated.
No, the person would not need separate Node. js installed. By embedding Chromium and Node. js into its binary, Electron allows you to maintain one JavaScript codebase and create cross-platform apps that work on Windows, macOS, and Linux — no native development experience required.
electron-builder is a CLI tool that helps us create multi-platform distributions for Electron applications. It supports macOS, Windows, and Linux targets out of the box. It supports multiple file formats for each of these platforms such as dmg , pkg , mas and, mas-dev for macOS.
You could handle each Squirrel event and create shortcuts:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With