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

45 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2015-06-15 18:28:47 +00:00
{EventEmitter} = require 'events'
SquirrelUpdate = require './auto-updater/squirrel-update-win'
app = require('app')
2015-06-15 18:28:47 +00:00
2015-06-16 10:31:55 +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) ->
# set feed URL only when it hasn't been set before
unless @updateUrl
@updateUrl = updateUrl
2015-06-15 18:28:47 +00:00
checkForUpdates: ->
throw new Error('Update URL is not set') unless @updateUrl
@emit 'checking-for-update'
unless SquirrelUpdate.supported()
2015-06-15 18:28:47 +00:00
@emit 'update-not-available'
return
SquirrelUpdate.download (error, update) =>
2015-06-15 18:28:47 +00:00
if error?
@emit 'update-not-available'
return
unless update?
@emit 'update-not-available'
return
@emit 'update-available'
SquirrelUpdate.update @updateUrl, (error) =>
2015-06-15 18:28:47 +00:00
if error?
@emit 'update-not-available'
return
# info about the newly installed version and a function any of the event listeners can call to restart the application
2015-06-15 18:28:47 +00:00
@emit 'update-downloaded', {}, update.releaseNotes, update.version, new Date(), @updateUrl, => @quitAndInstall()
module.exports = new AutoUpdater()