electron/atom/browser/api/lib/auto-updater/auto-updater-win.coffee

43 lines
1.2 KiB
CoffeeScript
Raw Normal View History

app = require 'app'
url = require 'url'
2015-06-15 18:28:47 +00:00
{EventEmitter} = require 'events'
squirrelUpdate = require './squirrel-update-win'
2015-06-15 18:28:47 +00:00
class AutoUpdater extends EventEmitter
2015-06-15 18:28:47 +00:00
quitAndInstall: ->
squirrelUpdate.processStart()
app.quit()
2015-06-15 18:28:47 +00:00
setFeedUrl: (updateUrl) ->
@updateUrl = updateUrl
2015-06-15 18:28:47 +00:00
checkForUpdates: ->
return @emitError 'Update URL is not set' unless @updateUrl
return @emitError 'Can not find Squirrel' unless squirrelUpdate.supported()
2015-06-15 18:28:47 +00:00
@emit 'checking-for-update'
squirrelUpdate.download @updateUrl, (error, update) =>
return @emitError error if error?
return @emit 'update-not-available' unless update?
2015-06-15 18:28:47 +00:00
@emit 'update-available'
2015-06-15 18:28:47 +00:00
squirrelUpdate.update @updateUrl, (error) =>
return @emitError error if error?
2015-06-15 18:28:47 +00:00
{releaseNotes, version} = update
# Following information is not available on Windows, so fake them.
date = new Date
url = @updateUrl
2015-06-15 18:28:47 +00:00
@emit 'update-downloaded', {}, releaseNotes, version, date, url, => @quitAndInstall()
2015-06-15 18:28:47 +00:00
# Private: Emit both error object and message, this is to keep compatibility
# with Old APIs.
emitError: (message) ->
@emit 'error', new Error(message), message
2015-06-15 18:28:47 +00:00
module.exports = new AutoUpdater