From 8366437b7eb49b6e424f6fce01ace2b19b02d498 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Fri, 22 Nov 2024 21:39:06 +0100 Subject: [PATCH] Add squirrel handler --- main.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index a3ced3d..15a185c 100644 --- a/main.js +++ b/main.js @@ -95,4 +95,54 @@ ipcMain.handle('install-package', async (event, aPackage, serialPort, compileFil console.error(`Failed to install package ${packageDesignator}:`, error); return { success: false, error: error.message }; } -}); \ No newline at end of file +}); + +// Handle auto updater events +function handleSquirrelEvent() { + if (process.argv.length === 1) { + return false; + } + + const ChildProcess = require('child_process'); + + 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': + // Install desktop and start menu shortcuts + spawnUpdate(['--createShortcut', exeName]); + setTimeout(app.quit, 1000); + return true; + case '--squirrel-uninstall': + // 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; + } +}; \ No newline at end of file