initial idea
This commit is contained in:
parent
827741a9c6
commit
621178f558
3 changed files with 108 additions and 1 deletions
60
atom/browser/api/lib/auto-updater/auto-updater-win.coffee
Normal file
60
atom/browser/api/lib/auto-updater/auto-updater-win.coffee
Normal file
|
@ -0,0 +1,60 @@
|
|||
{EventEmitter} = require 'events'
|
||||
SquirrelUpdate = require './auto-updater/squirrel-update-win'
|
||||
|
||||
class AutoUpdater
|
||||
@__proto__ = EventEmitter.prototype
|
||||
|
||||
quitAndInstall: ->
|
||||
# TODO
|
||||
|
||||
setFeedUrl: (@updateUrl) ->
|
||||
|
||||
checkForUpdates: ->
|
||||
throw new Error('Update URL is not set') unless @updateUrl
|
||||
|
||||
@emit 'checking-for-update'
|
||||
|
||||
unless SquirrelUpdate.existsSync()
|
||||
@emit 'update-not-available'
|
||||
return
|
||||
|
||||
@downloadUpdate (error, update) =>
|
||||
if error?
|
||||
@emit 'update-not-available'
|
||||
return
|
||||
|
||||
unless update?
|
||||
@emit 'update-not-available'
|
||||
return
|
||||
|
||||
@emit 'update-available'
|
||||
|
||||
@installUpdate (error) =>
|
||||
if error?
|
||||
@emit 'update-not-available'
|
||||
return
|
||||
|
||||
@emit 'update-downloaded', {}, update.releaseNotes, update.version, new Date(), @updateUrl, => @quitAndInstall()
|
||||
|
||||
downloadUpdate: (callback) ->
|
||||
SquirrelUpdate.spawn ['--download', @updateUrl], (error, stdout) ->
|
||||
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) ->
|
||||
SquirrelUpdate.spawn(['--update', @updateUrl], callback)
|
||||
|
||||
supportsUpdates: ->
|
||||
SquirrelUpdate.existsSync()
|
||||
|
||||
|
||||
module.exports = new AutoUpdater()
|
Loading…
Add table
Add a link
Reference in a new issue