Skip to content

Commit

Permalink
Add squirrel handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed Nov 22, 2024
1 parent 9058301 commit 8366437
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
});
});

// 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;
}
};

0 comments on commit 8366437

Please sign in to comment.