Save point before Boss Fight

This commit is contained in:
Paul Betts
2014-10-13 14:46:33 -07:00
committed by Kevin Sawicki
parent 379bd852d2
commit 7381bd09b1

View File

@@ -1,15 +1,58 @@
_ = require 'underscore-plus'
path = require 'path'
fs = require 'fs'
{EventEmitter} = require 'events'
{BufferedProcess} = require 'atom'
module.exports =
class AutoUpdater
_.extend @prototype, EventEmitter.prototype
setFeedUrl: ->
console.log 'setFeedUrl'
setFeedUrl: (url) ->
@updateUrl = url
quitAndInstall: ->
console.log 'quitAndInstall'
checkForUpdates: ->
console.log 'checkForUpdates'
throw new Error("Update URL is not set") unless @updateUrl
emit 'checking-for-update'
updateDotExe = path.join(path.dirName(process.execPath), '..', 'update.exe')
unless fs.existsSync(updateDotExe)
console.log 'Running developer or Chocolatey version of Atom, skipping'
emit 'update-not-available'
return
args = ['--update', @updateUrl]
updateJson = ""
ps = new BufferedProcess
command: updateDotExe,
args,
stdout: (output) -> updateJson += output
exit: (exitCode) ->
unless exitCode is 0
console.log 'Failed to update: ' + exitCode + ' - ' + updateJson
emit 'update-not-available'
return
updateInfo = null
try
updateInfo = JSON.parse updateJson
catch ex
console.log "Update JSON isn't valid: " + updateJson
emit 'update-not-available'
return
unless updateInfo and updateInfo.releasesToApply.length > 0
console.log "You're on the latest version!"
emit 'update-not-available'
return
# We don't have separate "check for update" and "download" in Squirrel,
# we always just download
emit 'update-available'
emit 'update-downloaded', {}