Add autoUpdater shim for Windows

This commit is contained in:
probablycorey
2014-07-07 17:06:28 -07:00
parent 68144681b2
commit 44e121c997

View File

@@ -1,3 +1,4 @@
https = require 'https'
autoUpdater = require 'auto-updater'
dialog = require 'dialog'
_ = require 'underscore-plus'
@@ -16,11 +17,15 @@ class AutoUpdateManager
constructor: (@version) ->
@state = IDLE_STATE
@feedUrl = "https://atom.io/api/updates?version=#{@version}"
if process.platform is 'win32'
autoUpdater.checkForUpdates = => @checkForUpdatesShim()
# Only released versions should check for updates.
return if /\w{7}/.test(@version)
autoUpdater.setFeedUrl "https://atom.io/api/updates?version=#{@version}"
autoUpdater.setFeedUrl @feedUrl
autoUpdater.on 'checking-for-update', =>
@setState(CHECKING_STATE)
@@ -41,6 +46,22 @@ class AutoUpdateManager
@check(hidePopups: true)
# Windows doesn't have an auto-updater, so use this method to shim the events.
checkForUpdatesShim: ->
autoUpdater.emit 'checking-for-update'
request = https.get @feedUrl, (response) ->
if response.statusCode == 200
body = ""
response.on 'data', (chunk) -> body += chunk
response.on 'end', ->
{notes, name} = JSON.parse(body)
autoUpdater.emit 'update-downloaded', notes, name
else
autoUpdater.emit 'update-not-available', notes, name
request.on 'error', (error) ->
autoUpdater.emit 'error', error.message
emitUpdateAvailableEvent: (windows...) ->
return unless @releaseVersion? and @releaseNotes
for atomWindow in windows