1+ const app = require ( 'electron' ) . app
2+
3+ if ( handleSquirrelEvent ( ) ) {
4+ return
5+ }
6+
7+ function handleSquirrelEvent ( ) {
8+ if ( process . argv . length === 1 ) {
9+ return false
10+ }
11+
12+ const ChildProcess = require ( 'child_process' )
13+ const path = require ( 'path' )
14+ const appFolder = path . resolve ( process . execPath , '..' )
15+ const rootAtomFolder = path . resolve ( appFolder , '..' )
16+ const updateDotExe = path . resolve ( path . join ( rootAtomFolder , 'Update.exe' ) )
17+ const exeName = path . basename ( process . execPath )
18+
19+ const spawn = function ( command , args ) {
20+ let spawnedProcess , error
21+
22+ try {
23+ spawnedProcess = ChildProcess . spawn ( command , args , { detached : true } )
24+ } catch ( error ) { }
25+
26+ return spawnedProcess
27+ }
28+
29+ const spawnUpdate = function ( args ) {
30+ return spawn ( updateDotExe , args )
31+ }
32+
33+ const squirrelEvent = process . argv [ 1 ]
34+ switch ( squirrelEvent ) {
35+ case '--squirrel-install' :
36+ case '--squirrel-updated' :
37+ // Install desktop and start menu shortcuts
38+ spawnUpdate ( [ '--createShortcut' , exeName ] )
39+ setTimeout ( app . quit , 1000 )
40+ return true
41+
42+ case '--squirrel-uninstall' :
43+ // Remove desktop and start menu shortcuts
44+ spawnUpdate ( [ '--removeShortcut' , exeName ] )
45+ setTimeout ( app . quit , 1000 )
46+ return true
47+
48+ case '--squirrel-obsolete' :
49+ app . quit ( )
50+ return true
51+ }
52+ }
0 commit comments