 _ = require 'underscore-plus'
 path = require 'path'
 fs = require 'fs'
+shellAutoUpdater = require 'auto-updater'
 
 {EventEmitter} = require 'events'
 {BufferedProcess} = require 'atom'

      stdout: (output) -> updateOutput += output
      exit: (exitCode) ->
        unless exitCode is 0
          console.log 'Failed to update: ' + exitCode + ' - ' + updateJson
          emit 'update-not-available'
          return


    @updateUrl = url

  quitAndInstall: ->
    updateDotExe = path.join(path.dirName(process.execPath), '..', 'update.exe')
      unless fs.existsSync(updateDotExe)
        console.log 'Running developer or Chocolatey version of Atom, skipping'
        return

    updateOutput = ""
    ps = new BufferedProcess
      command: updateDotExe,
      args: ['--update', @updateUrl]
      stdout: (o) -> updateOutput += o
      exit: (exitCode) ->
        unless exitCode is 0
          console.log 'Failed to update: ' + exitCode + ' - ' + updateOutput
          return

        dontcare = new BufferedProcess
          command: updateDotExe,
          args: ['--processStart', 'atom.exe']

        shellAutoUpdater.quitAndInstall()

  checkForUpdates: ->
    throw new Error("Update URL is not set") unless @updateUrl
