Migrate to block comments
This commit is contained in:
parent
630cd091a0
commit
403870a27e
44 changed files with 538 additions and 437 deletions
|
@ -28,14 +28,16 @@ class AutoUpdater extends EventEmitter
|
|||
return @emitError error if error?
|
||||
|
||||
{releaseNotes, version} = update
|
||||
# Following information is not available on Windows, so fake them.
|
||||
### Following information is not available on Windows, so fake them. ###
|
||||
date = new Date
|
||||
url = @updateURL
|
||||
|
||||
@emit 'update-downloaded', {}, releaseNotes, version, date, url, => @quitAndInstall()
|
||||
|
||||
# Private: Emit both error object and message, this is to keep compatibility
|
||||
# with Old APIs.
|
||||
###
|
||||
Private: Emit both error object and message, this is to keep compatibility
|
||||
with Old APIs.
|
||||
###
|
||||
emitError: (message) ->
|
||||
@emit 'error', new Error(message), message
|
||||
|
||||
|
|
|
@ -2,17 +2,21 @@ fs = require 'fs'
|
|||
path = require 'path'
|
||||
{spawn} = require 'child_process'
|
||||
|
||||
appFolder = path.dirname process.execPath # i.e. my-app/app-0.1.13/
|
||||
updateExe = path.resolve appFolder, '..', 'Update.exe' # i.e. my-app/Update.exe
|
||||
### i.e. my-app/app-0.1.13/ ###
|
||||
appFolder = path.dirname process.execPath
|
||||
### i.e. my-app/Update.exe ###
|
||||
updateExe = path.resolve appFolder, '..', 'Update.exe'
|
||||
exeName = path.basename process.execPath
|
||||
|
||||
# Spawn a command and invoke the callback when it completes with an error
|
||||
# and the output from standard out.
|
||||
###
|
||||
Spawn a command and invoke the callback when it completes with an error
|
||||
and the output from standard out.
|
||||
###
|
||||
spawnUpdate = (args, detached, callback) ->
|
||||
try
|
||||
spawnedProcess = spawn updateExe, args, {detached}
|
||||
catch error
|
||||
# Shouldn't happen, but still guard it.
|
||||
### Shouldn't happen, but still guard it. ###
|
||||
process.nextTick -> callback error
|
||||
return
|
||||
|
||||
|
@ -26,27 +30,27 @@ spawnUpdate = (args, detached, callback) ->
|
|||
errorEmitted = true
|
||||
callback error
|
||||
spawnedProcess.on 'exit', (code, signal) ->
|
||||
# We may have already emitted an error.
|
||||
### We may have already emitted an error. ###
|
||||
return if errorEmitted
|
||||
|
||||
# Process terminated with error.
|
||||
### Process terminated with error. ###
|
||||
if code isnt 0
|
||||
return callback "Command failed: #{signal ? code}\n#{stderr}"
|
||||
|
||||
# Success.
|
||||
### Success. ###
|
||||
callback null, stdout
|
||||
|
||||
# Start an instance of the installed app.
|
||||
### Start an instance of the installed app. ###
|
||||
exports.processStart = (callback) ->
|
||||
spawnUpdate ['--processStart', exeName], true, ->
|
||||
|
||||
# Download the releases specified by the URL and write new results to stdout.
|
||||
### Download the releases specified by the URL and write new results to stdout. ###
|
||||
exports.download = (updateURL, callback) ->
|
||||
spawnUpdate ['--download', updateURL], false, (error, stdout) ->
|
||||
return callback(error) if error?
|
||||
|
||||
try
|
||||
# Last line of output is the JSON details about the releases
|
||||
### Last line of output is the JSON details about the releases ###
|
||||
json = stdout.trim().split('\n').pop()
|
||||
update = JSON.parse(json)?.releasesToApply?.pop?()
|
||||
catch
|
||||
|
@ -54,11 +58,11 @@ exports.download = (updateURL, callback) ->
|
|||
|
||||
callback null, update
|
||||
|
||||
# Update the application to the latest remote version specified by URL.
|
||||
### Update the application to the latest remote version specified by URL. ###
|
||||
exports.update = (updateURL, callback) ->
|
||||
spawnUpdate ['--update', updateURL], false, callback
|
||||
|
||||
# Is the Update.exe installed with the current application?
|
||||
### Is the Update.exe installed with the current application? ###
|
||||
exports.supported = ->
|
||||
try
|
||||
fs.accessSync updateExe, fs.R_OK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue