mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Consolidate squirrel update code
This commit is contained in:
parent
327e8476dd
commit
7ba47840d8
@ -15,8 +15,8 @@ process.on 'uncaughtException', (error={}) ->
|
||||
|
||||
start = ->
|
||||
if process.platform is 'win32'
|
||||
handleSquirrelEvents = require './squirrel-events'
|
||||
return if handleSquirrelEvents()
|
||||
SquirrelUpdate = require './squirrel-update'
|
||||
return if SquirrelUpdate.handleStartupEvent()
|
||||
|
||||
args = parseCommandLine()
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
app = require 'app'
|
||||
path = require 'path'
|
||||
SquirrelUpdate = require './squirrel-update'
|
||||
|
||||
spawnUpdateAndQuit = (option) ->
|
||||
exeName = path.basename(process.execPath)
|
||||
SquirrelUpdate.spawn ["--#{option}", exeName], -> app.quit()
|
||||
|
||||
module.exports = ->
|
||||
switch process.argv[1]
|
||||
when '--squirrel-install', '--squirrel-updated'
|
||||
spawnUpdateAndQuit('createShortcut')
|
||||
true
|
||||
when '--squirrel-uninstall'
|
||||
spawnUpdateAndQuit('removeShortcut')
|
||||
true
|
||||
when '--squirrel-obsolete'
|
||||
app.quit()
|
||||
true
|
||||
else
|
||||
false
|
@ -1,32 +1,53 @@
|
||||
app = require 'app'
|
||||
ChildProcess = require 'child_process'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
||||
updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
||||
exeName = path.basename(process.execPath)
|
||||
|
||||
module.exports =
|
||||
spawn: (args, callback) ->
|
||||
stdout = ''
|
||||
error = null
|
||||
# Spawn the Update.exe with the given arguments and invoke the callback when
|
||||
# the command completes.
|
||||
exports.spawn = (args, callback) ->
|
||||
stdout = ''
|
||||
error = null
|
||||
|
||||
args = args.map (arg) -> "\"#{arg.toString().replace(/"/g, '\\"')}\""
|
||||
if /\s/.test(updateDotExe)
|
||||
args.unshift("\"#{updateDotExe}\"")
|
||||
args = args.map (arg) -> "\"#{arg.toString().replace(/"/g, '\\"')}\""
|
||||
if /\s/.test(updateDotExe)
|
||||
args.unshift("\"#{updateDotExe}\"")
|
||||
else
|
||||
args.unshift(updateDotExe)
|
||||
|
||||
args = ['/s', '/c', "\"#{cmdArgs.join(' ')}\""]
|
||||
command = process.env.comspec or 'cmd.exe'
|
||||
|
||||
updateProcess = ChildProcess.spawn(command, args, windowsVerbatimArguments: true)
|
||||
updateProcess.stdout.on 'data', (data) -> stdout += data
|
||||
updateProcess.on 'error', (processError) -> error ?= processError
|
||||
updateProcess.on 'close', (code, signal) ->
|
||||
error ?= new Error("Command failed: #{signal}") if code isnt 0
|
||||
error?.code ?= code
|
||||
error?.stdout ?= stdout
|
||||
callback(error, stdout)
|
||||
|
||||
undefined
|
||||
|
||||
# Is the Update.exe installed with Atom?
|
||||
exports.existsSync = ->
|
||||
fs.existsSync(updateDotExe)
|
||||
|
||||
# Handle squirrel events denoted by --squirrel-* command line arguments.
|
||||
exports.handleStartupEvent = ->
|
||||
switch process.argv[1]
|
||||
when '--squirrel-install', '--squirrel-updated'
|
||||
exports.spawn ['--createShortcut', exeName], -> app.quit()
|
||||
spawnUpdateAndQuit('')
|
||||
true
|
||||
when '--squirrel-uninstall'
|
||||
exports.spawn ['--removeShortcut', exeName], -> app.quit()
|
||||
true
|
||||
when '--squirrel-obsolete'
|
||||
app.quit()
|
||||
true
|
||||
else
|
||||
args.unshift(updateDotExe)
|
||||
|
||||
args = ['/s', '/c', "\"#{cmdArgs.join(' ')}\""]
|
||||
command = process.env.comspec or 'cmd.exe'
|
||||
|
||||
updateProcess = ChildProcess.spawn(command, args, windowsVerbatimArguments: true)
|
||||
updateProcess.stdout.on 'data', (data) -> stdout += data
|
||||
updateProcess.on 'error', (processError) -> error ?= processError
|
||||
updateProcess.on 'close', (code, signal) ->
|
||||
error ?= new Error("Command failed: #{signal}") if code isnt 0
|
||||
error?.code ?= code
|
||||
error?.stdout ?= stdout
|
||||
callback(error, stdout)
|
||||
|
||||
undefined
|
||||
|
||||
existsSync: ->
|
||||
fs.existsSync(updateDotExe)
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user