-autoUpdater = require 'auto-updater'
+autoUpdater = null
 _ = require 'underscore-plus'
 {EventEmitter} = require 'events'
 

  constructor: (@version) ->
    @state = IdleState
    @feedUrl = "https://atom.io/api/updates?version=#{@version}"

    if process.platform is 'win32'
      autoUpdater.checkForUpdates = => @checkForUpdatesShim()

  checkForUpdatesShim: ->
    autoUpdater.emit 'checking-for-update'

    https = require 'https'
    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', null, notes, name
      else
        autoUpdater.emit 'update-not-available'

    request.on 'error', (error) ->
      autoUpdater.emit 'error', null, error.message

  emitUpdateAvailableEvent: (windows...) ->
    return unless @releaseVersion? and @releaseNotes
