Initial commit.
This commit is contained in:
commit
b022bca449
20 changed files with 7405 additions and 0 deletions
54
src/squirrelEvents.js
Normal file
54
src/squirrelEvents.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
const { app } = require('electron');
|
||||
const ChildProcess = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function handleSquirrelEvent() {
|
||||
if (process.argv.length === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
try {
|
||||
spawnedProcess = ChildProcess.spawn(command, args, { detached: true });
|
||||
} catch (error) {
|
||||
// Log error or handle appropriately
|
||||
}
|
||||
return spawnedProcess;
|
||||
};
|
||||
|
||||
const spawnUpdate = function (args) {
|
||||
return spawn(updateDotExe, args);
|
||||
};
|
||||
|
||||
const squirrelEvent = process.argv[1];
|
||||
switch (squirrelEvent) {
|
||||
case '--squirrel-install':
|
||||
case '--squirrel-updated':
|
||||
spawnUpdate(['--createShortcut', exeName]);
|
||||
const desktopShortcutPath = path.join(app.getPath('desktop'), `${exeName}.lnk`);
|
||||
if (fs.existsSync(desktopShortcutPath)) {
|
||||
fs.unlinkSync(desktopShortcutPath);
|
||||
}
|
||||
setTimeout(app.quit, 1000);
|
||||
return true;
|
||||
|
||||
case '--squirrel-uninstall':
|
||||
spawnUpdate(['--removeShortcut', exeName]);
|
||||
setTimeout(app.quit, 1000);
|
||||
return true;
|
||||
|
||||
case '--squirrel-obsolete':
|
||||
app.quit();
|
||||
return true;
|
||||
}
|
||||
return false; // Ensure a boolean is always returned
|
||||
}
|
||||
|
||||
module.exports = { handleSquirrelEvent };
|
Loading…
Add table
Add a link
Reference in a new issue