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

43 lines
1.2 KiB
CoffeeScript
Raw Normal View History

{app} = require 'electron'
2015-06-15 18:28:47 +00:00
{EventEmitter} = require 'events'
url = require 'url'
2015-06-15 18:28:47 +00:00
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
2015-11-13 08:03:40 +00:00
setFeedURL: (updateURL) ->
@updateURL = updateURL
2015-06-15 18:28:47 +00:00
checkForUpdates: ->
2015-11-13 08:03:40 +00:00
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'
2015-11-13 08:03:40 +00:00
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
2015-11-13 08:03:40 +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
2015-11-13 08:03:40 +00:00
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