@@ -9,7 +9,6 @@ const appFolder = path.resolve(process.execPath, '..')
99const rootAtomFolder = path . resolve ( appFolder , '..' )
1010const binFolder = path . join ( rootAtomFolder , 'bin' )
1111const updateDotExe = path . join ( rootAtomFolder , 'Update.exe' )
12- const exeName = path . basename ( process . execPath )
1312
1413if ( process . env . SystemRoot ) {
1514 const system32Path = path . join ( process . env . SystemRoot , 'System32' )
@@ -30,17 +29,20 @@ const spawnUpdate = (args, callback) => Spawner.spawn(updateDotExe, args, callba
3029// This is done by adding .cmd shims to the root bin folder in the Atom
3130// install directory that point to the newly installed versions inside
3231// the versioned app directories.
33- const addCommandsToPath = callback => {
32+ const addCommandsToPath = ( exeName , callback ) => {
33+ const atomCmdName = exeName . replace ( '.exe' , '.cmd' )
34+ const apmCmdName = atomCmdName . replace ( 'atom' , 'apm' )
35+
3436 const installCommands = callback => {
35- const atomCommandPath = path . join ( binFolder , 'atom.cmd' )
37+ const atomCommandPath = path . join ( binFolder , atomCmdName )
3638 const relativeAtomPath = path . relative ( binFolder , path . join ( appFolder , 'resources' , 'cli' , 'atom.cmd' ) )
3739 const atomCommand = `@echo off\r\n\"%~dp0\\${ relativeAtomPath } \" %*`
3840
3941 const atomShCommandPath = path . join ( binFolder , 'atom' )
4042 const relativeAtomShPath = path . relative ( binFolder , path . join ( appFolder , 'resources' , 'cli' , 'atom.sh' ) )
4143 const atomShCommand = `#!/bin/sh\r\n\"$(dirname \"$0\")/${ relativeAtomShPath . replace ( / \\ / g, '/' ) } \" \"$@\"\r\necho`
4244
43- const apmCommandPath = path . join ( binFolder , 'apm.cmd' )
45+ const apmCommandPath = path . join ( binFolder , apmCmdName )
4446 const relativeApmPath = path . relative ( binFolder , path . join ( process . resourcesPath , 'app' , 'apm' , 'bin' , 'apm.cmd' ) )
4547 const apmCommand = `@echo off\r\n\"%~dp0\\${ relativeApmPath } \" %*`
4648
@@ -94,32 +96,35 @@ const removeCommandsFromPath = callback =>
9496 }
9597 } )
9698
99+ const getExeName = ( app ) => path . basename ( app . getPath ( 'exe' ) )
100+
97101// Create a desktop and start menu shortcut by using the command line API
98102// provided by Squirrel's Update.exe
99- const createShortcuts = ( locations , callback ) => spawnUpdate ( [ '--createShortcut' , exeName , '-l' , locations . join ( ',' ) ] , callback )
103+ const createShortcuts = ( exeName , locations , callback ) =>
104+ spawnUpdate ( [ '--createShortcut' , exeName , '-l' , locations . join ( ',' ) ] , callback )
100105
101106// Update the desktop and start menu shortcuts by using the command line API
102107// provided by Squirrel's Update.exe
103- const updateShortcuts = ( app , callback ) => {
108+ const updateShortcuts = ( appName , exeName , callback ) => {
104109 const homeDirectory = fs . getHomeDirectory ( )
105110 if ( homeDirectory ) {
106- const desktopShortcutPath = path . join ( homeDirectory , 'Desktop' , `${ app . getName ( ) } .lnk` )
111+ const desktopShortcutPath = path . join ( homeDirectory , 'Desktop' , `${ appName } .lnk` )
107112 // Check if the desktop shortcut has been previously deleted and
108113 // and keep it deleted if it was
109114 fs . exists ( desktopShortcutPath , ( desktopShortcutExists ) => {
110115 const locations = [ 'StartMenu' ]
111116 if ( desktopShortcutExists ) { locations . push ( 'Desktop' ) }
112117
113- createShortcuts ( locations , callback )
118+ createShortcuts ( exeName , locations , callback )
114119 } )
115120 } else {
116- createShortcuts ( [ 'Desktop' , 'StartMenu' ] , callback )
121+ createShortcuts ( exeName , [ 'Desktop' , 'StartMenu' ] , callback )
117122 }
118123}
119124
120125// Remove the desktop and start menu shortcuts by using the command line API
121126// provided by Squirrel's Update.exe
122- const removeShortcuts = callback => spawnUpdate ( [ '--removeShortcut' , exeName ] , callback )
127+ const removeShortcuts = ( exeName , callback ) => spawnUpdate ( [ '--removeShortcut' , exeName ] , callback )
123128
124129exports . spawn = spawnUpdate
125130
@@ -129,52 +134,38 @@ exports.existsSync = () => fs.existsSync(updateDotExe)
129134// Restart Atom using the version pointed to by the atom.cmd shim
130135exports . restartAtom = ( app ) => {
131136 let args
137+ const exeName = getExeName ( app )
138+ const atomCmdName = exeName . replace ( '.exe' , '.cmd' )
132139 if ( global . atomApplication && global . atomApplication . lastFocusedWindow ) {
133140 const { projectPath} = global . atomApplication . lastFocusedWindow
134141 if ( projectPath ) args = [ projectPath ]
135142 }
136- app . once ( 'will-quit' , ( ) => Spawner . spawn ( path . join ( binFolder , 'atom.cmd' ) , args ) )
143+ app . once ( 'will-quit' , ( ) => Spawner . spawn ( path . join ( binFolder , atomCmdName ) , args ) )
137144 app . quit ( )
138145}
139146
140- const updateContextMenus = callback =>
141- WinShell . fileContextMenu . update ( ( ) =>
142- WinShell . folderContextMenu . update ( ( ) =>
143- WinShell . folderBackgroundContextMenu . update ( ( ) => callback ( ) )
144- )
145- )
146-
147147// Handle squirrel events denoted by --squirrel-* command line arguments.
148148exports . handleStartupEvent = ( app , squirrelCommand ) => {
149+ const exeName = getExeName ( app )
149150 switch ( squirrelCommand ) {
150151 case '--squirrel-install' :
151- createShortcuts ( [ 'Desktop' , 'StartMenu' ] , ( ) =>
152- addCommandsToPath ( ( ) =>
153- WinShell . fileHandler . register ( ( ) =>
154- updateContextMenus ( ( ) => app . quit ( ) )
155- )
152+ createShortcuts ( exeName , [ 'Desktop' , 'StartMenu' ] , ( ) =>
153+ addCommandsToPath ( exeName , ( ) =>
154+ WinShell . registerShellIntegration ( app . getName ( ) , ( ) => app . quit ( ) )
156155 )
157156 )
158157 return true
159158 case '--squirrel-updated' :
160- updateShortcuts ( app , ( ) =>
161- addCommandsToPath ( ( ) =>
162- WinShell . fileHandler . update ( ( ) =>
163- updateContextMenus ( ( ) => app . quit ( ) )
164- )
159+ updateShortcuts ( app . getName ( ) , exeName , ( ) =>
160+ addCommandsToPath ( exeName , ( ) =>
161+ WinShell . updateShellIntegration ( app . getName ( ) , ( ) => app . quit ( ) )
165162 )
166163 )
167164 return true
168165 case '--squirrel-uninstall' :
169- removeShortcuts ( ( ) =>
166+ removeShortcuts ( exeName , ( ) =>
170167 removeCommandsFromPath ( ( ) =>
171- WinShell . fileHandler . deregister ( ( ) =>
172- WinShell . fileContextMenu . deregister ( ( ) =>
173- WinShell . folderContextMenu . deregister ( ( ) =>
174- WinShell . folderBackgroundContextMenu . deregister ( ( ) => app . quit ( ) )
175- )
176- )
177- )
168+ WinShell . deregisterShellIntegration ( app . getName ( ) , ( ) => app . quit ( ) )
178169 )
179170 )
180171 return true
0 commit comments