-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsquirrel.js
44 lines (38 loc) · 1.16 KB
/
squirrel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-disable @typescript-eslint/no-var-requires */
const childProcess = require('child_process');
const path = require('path');
const spawn = (command, args, done) => {
let spawnedProcess;
try {
spawnedProcess = childProcess
.spawn(command, args, { detached: true })
.on('close', done);
}
catch (e) {}
return spawnedProcess;
};
const squirrel = (argv, done) => {
if (process.platform !== 'win32') {
return true;
}
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);
if (argv.squirrelInstall) {
// install desktop and start menu shortcuts
spawn(updateDotExe, ['--createShortcut', exeName], done);
}
else if (argv.squirrelUninstall) {
// remove desktop and start menu shortcuts
spawn(updateDotExe, ['--removeShortcut', exeName], done);
}
else if (argv.squirrelUpdated || argv.squirrelObsolete) {
done();
}
else {
// no squirrel, we should continue to app start...
return true;
}
};
module.exports = { squirrel };