mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-13 11:38:31 +08:00
fix(squirrel): fix win32 update to enable restart and launch from path
This commit is contained in:
parent
ba9af70b16
commit
9726618069
1 changed files with 84 additions and 4 deletions
|
@ -54,11 +54,23 @@ spawnSetx = (args, callback) ->
|
||||||
spawnUpdate = (args, callback) ->
|
spawnUpdate = (args, callback) ->
|
||||||
spawn(updateDotExe, args, callback)
|
spawn(updateDotExe, args, callback)
|
||||||
|
|
||||||
|
isAscii = (text) ->
|
||||||
|
index = 0
|
||||||
|
while index < text.length
|
||||||
|
return false if text.charCodeAt(index) > 127
|
||||||
|
index++
|
||||||
|
true
|
||||||
|
|
||||||
# Get the user's PATH environment variable registry value.
|
# Get the user's PATH environment variable registry value.
|
||||||
getPath = (callback) ->
|
getPath = (callback) ->
|
||||||
spawnReg ['query', environmentKeyPath, '/v', 'Path'], (error, stdout) ->
|
spawnReg ['query', environmentKeyPath, '/v', 'Path'], (error, stdout) ->
|
||||||
if error?
|
if error?
|
||||||
if error.code is 1
|
if error.code is 1
|
||||||
|
# FIXME Don't overwrite path when reading value is disabled
|
||||||
|
# https://github.com/atom/atom/issues/5092
|
||||||
|
if stdout.indexOf('ERROR: Registry editing has been disabled by your administrator.') isnt -1
|
||||||
|
return callback(error)
|
||||||
|
|
||||||
# The query failed so the Path does not exist yet in the registry
|
# The query failed so the Path does not exist yet in the registry
|
||||||
return callback(null, '')
|
return callback(null, '')
|
||||||
else
|
else
|
||||||
|
@ -74,10 +86,75 @@ getPath = (callback) ->
|
||||||
segments = lines[lines.length - 1]?.split(' ')
|
segments = lines[lines.length - 1]?.split(' ')
|
||||||
if segments[1] is 'Path' and segments.length >= 3
|
if segments[1] is 'Path' and segments.length >= 3
|
||||||
pathEnv = segments?[3..].join(' ')
|
pathEnv = segments?[3..].join(' ')
|
||||||
callback(null, pathEnv)
|
if isAscii(pathEnv)
|
||||||
|
callback(null, pathEnv)
|
||||||
|
else
|
||||||
|
# FIXME Don't corrupt non-ASCII PATH values
|
||||||
|
# https://github.com/atom/atom/issues/5063
|
||||||
|
callback(new Error('PATH contains non-ASCII values'))
|
||||||
else
|
else
|
||||||
callback(new Error('Registry query for PATH failed'))
|
callback(new Error('Registry query for PATH failed'))
|
||||||
|
|
||||||
|
# Add atom and apm to the PATH
|
||||||
|
#
|
||||||
|
# This is done by adding .cmd shims to the root bin folder in the N1
|
||||||
|
# install directory that point to the newly installed versions inside
|
||||||
|
# the versioned app directories.
|
||||||
|
addCommandsToPath = (callback) ->
|
||||||
|
installCommands = (callback) ->
|
||||||
|
nylasCommandPath = path.join(binFolder, 'N1.cmd')
|
||||||
|
relativeN1Path = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'N1.cmd'))
|
||||||
|
nylasCommand = "@echo off\r\n\"%~dp0\\#{relativeN1Path}\" %*"
|
||||||
|
|
||||||
|
nylasShCommandPath = path.join(binFolder, 'N1')
|
||||||
|
relativeN1ShPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'N1.sh'))
|
||||||
|
nylasShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeN1ShPath.replace(/\\/g, '/')}\" \"$@\""
|
||||||
|
|
||||||
|
apmCommandPath = path.join(binFolder, 'apm.cmd')
|
||||||
|
relativeApmPath = path.relative(binFolder, path.join(process.resourcesPath, 'app', 'apm', 'bin', 'apm.cmd'))
|
||||||
|
apmCommand = "@echo off\r\n\"%~dp0\\#{relativeApmPath}\" %*"
|
||||||
|
|
||||||
|
apmShCommandPath = path.join(binFolder, 'apm')
|
||||||
|
relativeApmShPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'apm.sh'))
|
||||||
|
apmShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeApmShPath.replace(/\\/g, '/')}\" \"$@\""
|
||||||
|
|
||||||
|
fs.writeFile nylasCommandPath, nylasCommand, ->
|
||||||
|
fs.writeFile nylasShCommandPath, nylasShCommand, ->
|
||||||
|
fs.writeFile apmCommandPath, apmCommand, ->
|
||||||
|
fs.writeFile apmShCommandPath, apmShCommand, ->
|
||||||
|
callback()
|
||||||
|
|
||||||
|
addBinToPath = (pathSegments, callback) ->
|
||||||
|
pathSegments.push(binFolder)
|
||||||
|
newPathEnv = pathSegments.join(';')
|
||||||
|
spawnSetx(['Path', newPathEnv], callback)
|
||||||
|
|
||||||
|
installCommands (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
|
||||||
|
getPath (error, pathEnv) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
|
||||||
|
pathSegments = pathEnv.split(/;+/).filter (pathSegment) -> pathSegment
|
||||||
|
if pathSegments.indexOf(binFolder) is -1
|
||||||
|
addBinToPath(pathSegments, callback)
|
||||||
|
else
|
||||||
|
callback()
|
||||||
|
|
||||||
|
# Remove N1 and apm from the PATH
|
||||||
|
removeCommandsFromPath = (callback) ->
|
||||||
|
getPath (error, pathEnv) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
|
||||||
|
pathSegments = pathEnv.split(/;+/).filter (pathSegment) ->
|
||||||
|
pathSegment and pathSegment isnt binFolder
|
||||||
|
newPathEnv = pathSegments.join(';')
|
||||||
|
|
||||||
|
if pathEnv isnt newPathEnv
|
||||||
|
spawnSetx(['Path', newPathEnv], callback)
|
||||||
|
else
|
||||||
|
callback()
|
||||||
|
|
||||||
# Create a desktop and start menu shortcut by using the command line API
|
# Create a desktop and start menu shortcut by using the command line API
|
||||||
# provided by Squirrel's Update.exe
|
# provided by Squirrel's Update.exe
|
||||||
createShortcuts = (callback) ->
|
createShortcuts = (callback) ->
|
||||||
|
@ -123,15 +200,18 @@ exports.handleStartupEvent = (app, squirrelCommand) ->
|
||||||
switch squirrelCommand
|
switch squirrelCommand
|
||||||
when '--squirrel-install'
|
when '--squirrel-install'
|
||||||
createShortcuts ->
|
createShortcuts ->
|
||||||
app.quit()
|
addCommandsToPath ->
|
||||||
|
app.quit()
|
||||||
true
|
true
|
||||||
when '--squirrel-updated'
|
when '--squirrel-updated'
|
||||||
updateShortcuts ->
|
updateShortcuts ->
|
||||||
app.quit()
|
addCommandsToPath ->
|
||||||
|
app.quit()
|
||||||
true
|
true
|
||||||
when '--squirrel-uninstall'
|
when '--squirrel-uninstall'
|
||||||
removeShortcuts ->
|
removeShortcuts ->
|
||||||
app.quit()
|
removeCommandsFromPath ->
|
||||||
|
app.quit()
|
||||||
true
|
true
|
||||||
when '--squirrel-obsolete'
|
when '--squirrel-obsolete'
|
||||||
app.quit()
|
app.quit()
|
||||||
|
|
Loading…
Reference in a new issue