<commit_before>import Events from 'events'
import autoUpdater from 'auto-updater'

export default class AutoUpdateManager extends Events.EventEmitter {
  constructor (version, logger) {
    super()
    this.version = version
    // this.feedUrl = 'http://localhost:5000/updates?version=' + version
    this.feedUrl = 'https://api.hackermenu.io/updates?version=' + version
    this.state = AutoUpdateManager.IDLE_STATE
    this.logger = logger

    process.nextTick(this.setupAutoUpdater.bind(this))
  }

  setupAutoUpdater () {
    var self = this

    autoUpdater.on('error', function (event, message) {
      self.setState(AutoUpdateManager.ERROR_STATE)
      self.logger.error('auto-updater-manager.error', { error: message })
    })

    autoUpdater.setFeedUrl(this.feedUrl)

    autoUpdater.on('checking-for-update', function () {
      self.setState(AutoUpdateManager.CHECKING_STATE)
    })

    autoUpdater.on('update-not-available', function () {
      self.setState(AutoUpdateManager.NO_UPDATE_AVAILABLE_STATE)
    })

    autoUpdater.on('update-available', function () {
      self.setState(AutoUpdateManager.DOWNLOADING_STATE)
    })

    autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl) {
      self.setState(AutoUpdateManager.UPDATE_AVAILABLE_STATE)
      self.logger.info('auto-update-manager.update-downloaded', {releaseNotes: releaseNotes, releaseName: releaseName, releaseDate: releaseDate, updateUrl: updateUrl})

      self.emit('update-available', releaseName)
    })

    this.scheduleUpdateCheck()
  }

  setState (state) {
    this.state = state
    this.emit('state-changed', state)
    this.logger.info('auto-update-manager.state-changed', { state: state })
  }

  scheduleUpdateCheck () {
    var fourHours = 1000 * 60 * 60 * 4
    setInterval(this.checkForUpdates.bind(this), fourHours)
    this.checkForUpdates()
  }

  checkForUpdates () {
    autoUpdater.checkForUpdates()
  }

  quitAndInstall () {
    autoUpdater.quitAndInstall()
  }

 isUpdateAvailable () {
   return this.state === AutoUpdateManager.UPDATE_AVAILABLE_STATE
 }
}

AutoUpdateManager.IDLE_STATE = 'idle'
AutoUpdateManager.CHECKING_STATE = 'checking'
AutoUpdateManager.DOWNLOADING_STATE = 'downloading'
AutoUpdateManager.UPDATE_AVAILABLE_STATE = 'update-available'
AutoUpdateManager.NO_UPDATE_AVAILABLE_STATE = 'no-update-available'
AutoUpdateManager.ERROR_STATE = 'error'
<commit_msg>Fix update server URL<commit_after>import Events from 'events'
import autoUpdater from 'auto-updater'

export default class AutoUpdateManager extends Events.EventEmitter {
  constructor (version, logger) {
    super()
    this.version = version
    // this.feedUrl = 'http://localhost:5000/updates?version=' + version
    this.feedUrl = 'https://hackermenu.io/updates?version=' + version
    this.state = AutoUpdateManager.IDLE_STATE
    this.logger = logger

    process.nextTick(this.setupAutoUpdater.bind(this))
  }

  setupAutoUpdater () {
    var self = this

    autoUpdater.on('error', function (event, message) {
      self.setState(AutoUpdateManager.ERROR_STATE)
      self.logger.error('auto-updater-manager.error', { error: message })
    })

    autoUpdater.setFeedUrl(this.feedUrl)

    autoUpdater.on('checking-for-update', function () {
      self.setState(AutoUpdateManager.CHECKING_STATE)
    })

    autoUpdater.on('update-not-available', function () {
      self.setState(AutoUpdateManager.NO_UPDATE_AVAILABLE_STATE)
    })

    autoUpdater.on('update-available', function () {
      self.setState(AutoUpdateManager.DOWNLOADING_STATE)
    })

    autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl) {
      self.setState(AutoUpdateManager.UPDATE_AVAILABLE_STATE)
      self.logger.info('auto-update-manager.update-downloaded', {releaseNotes: releaseNotes, releaseName: releaseName, releaseDate: releaseDate, updateUrl: updateUrl})

      self.emit('update-available', releaseName)
    })

    this.scheduleUpdateCheck()
  }

  setState (state) {
    this.state = state
    this.emit('state-changed', state)
    this.logger.info('auto-update-manager.state-changed', { state: state })
  }

  scheduleUpdateCheck () {
    var fourHours = 1000 * 60 * 60 * 4
    setInterval(this.checkForUpdates.bind(this), fourHours)
    this.checkForUpdates()
  }

  checkForUpdates () {
    autoUpdater.checkForUpdates()
  }

  quitAndInstall () {
    autoUpdater.quitAndInstall()
  }

 isUpdateAvailable () {
   return this.state === AutoUpdateManager.UPDATE_AVAILABLE_STATE
 }
}

AutoUpdateManager.IDLE_STATE = 'idle'
AutoUpdateManager.CHECKING_STATE = 'checking'
AutoUpdateManager.DOWNLOADING_STATE = 'downloading'
AutoUpdateManager.UPDATE_AVAILABLE_STATE = 'update-available'
AutoUpdateManager.NO_UPDATE_AVAILABLE_STATE = 'no-update-available'
AutoUpdateManager.ERROR_STATE = 'error'

{'fraction_non_alphanumeric': 0.11746617466174662, 'fraction_numerical': 0.005330053300533005, 'mean_word_length': 4.28602383531961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5505327', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1509, 'n_words': 227}