move squirrel bahaviour into proper place
This commit is contained in:
parent
62882fe49e
commit
ae5411c37b
2 changed files with 32 additions and 26 deletions
|
@ -1,10 +1,12 @@
|
||||||
{EventEmitter} = require 'events'
|
{EventEmitter} = require 'events'
|
||||||
SquirrelUpdate = require './auto-updater/squirrel-update-win'
|
SquirrelUpdate = require './auto-updater/squirrel-update-win'
|
||||||
|
app = require('app')
|
||||||
|
|
||||||
class AutoUpdater extends EventEmitter
|
class AutoUpdater extends EventEmitter
|
||||||
|
|
||||||
quitAndInstall: ->
|
quitAndInstall: ->
|
||||||
# TODO
|
SquirrelUpdate.processStart ->
|
||||||
|
app.quit()
|
||||||
|
|
||||||
setFeedUrl: (updateUrl) ->
|
setFeedUrl: (updateUrl) ->
|
||||||
# set feed URL only when it hasn't been set before
|
# set feed URL only when it hasn't been set before
|
||||||
|
@ -36,27 +38,16 @@ class AutoUpdater extends EventEmitter
|
||||||
@emit 'update-not-available'
|
@emit 'update-not-available'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# info about the newly installed version and a function any of the event listeners can call to restart the application
|
||||||
@emit 'update-downloaded', {}, update.releaseNotes, update.version, new Date(), @updateUrl, => @quitAndInstall()
|
@emit 'update-downloaded', {}, update.releaseNotes, update.version, new Date(), @updateUrl, => @quitAndInstall()
|
||||||
|
|
||||||
downloadUpdate: (callback) ->
|
downloadUpdate: (callback) ->
|
||||||
SquirrelUpdate.spawn ['--download', @updateUrl], (error, stdout) ->
|
SquirrelUpdate.download(callback)
|
||||||
return callback(error) if error?
|
|
||||||
|
|
||||||
try
|
|
||||||
# Last line of output is the JSON details about the releases
|
|
||||||
json = stdout.trim().split('\n').pop()
|
|
||||||
update = JSON.parse(json)?.releasesToApply?.pop?()
|
|
||||||
catch error
|
|
||||||
error.stdout = stdout
|
|
||||||
return callback(error)
|
|
||||||
|
|
||||||
callback(null, update)
|
|
||||||
|
|
||||||
installUpdate: (callback) ->
|
installUpdate: (callback) ->
|
||||||
SquirrelUpdate.spawn(['--update', @updateUrl], callback)
|
SquirrelUpdate.update(@updateUrl, callback)
|
||||||
|
|
||||||
supportsUpdates: ->
|
supportsUpdates: ->
|
||||||
SquirrelUpdate.existsSync()
|
SquirrelUpdate.supported()
|
||||||
|
|
||||||
|
|
||||||
module.exports = new AutoUpdater()
|
module.exports = new AutoUpdater()
|
||||||
|
|
|
@ -9,11 +9,11 @@ exeName = path.basename(process.execPath)
|
||||||
|
|
||||||
# Spawn a command and invoke the callback when it completes with an error
|
# Spawn a command and invoke the callback when it completes with an error
|
||||||
# and the output from standard out.
|
# and the output from standard out.
|
||||||
spawn = (command, args, callback) ->
|
spawnUpdate = (args, callback) ->
|
||||||
stdout = ''
|
stdout = ''
|
||||||
|
|
||||||
try
|
try
|
||||||
spawnedProcess = ChildProcess.spawn(command, args)
|
spawnedProcess = ChildProcess.spawn(updateDotExe, args)
|
||||||
catch error
|
catch error
|
||||||
# Spawn can throw an error
|
# Spawn can throw an error
|
||||||
process.nextTick -> callback?(error, stdout)
|
process.nextTick -> callback?(error, stdout)
|
||||||
|
@ -29,14 +29,29 @@ spawn = (command, args, callback) ->
|
||||||
error?.stdout ?= stdout
|
error?.stdout ?= stdout
|
||||||
callback?(error, stdout)
|
callback?(error, stdout)
|
||||||
|
|
||||||
# Spawn the Update.exe with the given arguments and invoke the callback when
|
processStart = (callback) ->
|
||||||
# the command completes.
|
spawnUpdate(['--processStart', exeName], callback)
|
||||||
spawnUpdate = (args, callback) ->
|
|
||||||
spawn(updateDotExe, args, callback)
|
|
||||||
|
|
||||||
# Exports
|
download = (callback) ->
|
||||||
exports.spawn = spawnUpdate
|
spawnUpdate ['--download', @updateUrl], (error, stdout) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
|
||||||
# Is the Update.exe installed with Atom?
|
try
|
||||||
exports.existsSync = ->
|
# Last line of output is the JSON details about the releases
|
||||||
|
json = stdout.trim().split('\n').pop()
|
||||||
|
update = JSON.parse(json)?.releasesToApply?.pop?()
|
||||||
|
catch error
|
||||||
|
error.stdout = stdout
|
||||||
|
return callback(error)
|
||||||
|
|
||||||
|
callback(null, update)
|
||||||
|
|
||||||
|
update = (updateUrl, callback) ->
|
||||||
|
spawnUpdate ['--update', updateUrl], callback
|
||||||
|
|
||||||
|
# Is the Update.exe installed with the current application?
|
||||||
|
exports.supported = ->
|
||||||
fs.accessSync(updateDotExe, fs.R_OK)
|
fs.accessSync(updateDotExe, fs.R_OK)
|
||||||
|
exports.processStart = processStart
|
||||||
|
exports.download = download
|
||||||
|
exports.update = update
|
||||||
|
|
Loading…
Reference in a new issue