From 44e121c9974514d8ddb4791a1b2de257ffdaf1fc Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 7 Jul 2014 17:06:28 -0700 Subject: [PATCH] Add autoUpdater shim for Windows --- src/browser/auto-update-manager.coffee | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index cb76c2481..208364f23 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -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