<commit_before>const WindowManager = require('./window_manager')
const {autoUpdater} = require('electron-updater')

const log = require('cozy-desktop').default.logger({
  component: 'GUI:autoupdater'
})

const UPDATE_CHECK_TIMEOUT = 5000

module.exports = class UpdaterWM extends WindowManager {
  windowOptions () {
    return {
      title: 'UPDATER',
      width: 500,
      height: 400
    }
  }

  constructor (...opts) {
    autoUpdater.on('update-available', (info) => {
      this.clearTimeoutIfAny()
      log.info({update: info, skipped: this.skipped}, 'Update available')
      // Make sure UI don't show up in front of onboarding after timeout
      if (!this.skipped) this.show()
    })
    autoUpdater.on('update-not-available', (info) => {
      log.info({update: info}, 'No update available')
      this.afterUpToDate()
    })
    autoUpdater.on('error', (err) => {
      log.error({err}, 'Error in auto-updater! ')
      // May happen in dev because of code signature error. Not really an issue.
      this.afterUpToDate()
    })
    autoUpdater.on('download-progress', (progressObj) => {
      log.trace({progress: progressObj}, 'Downloading...')
      this.send('update-downloading', progressObj)
    })
    autoUpdater.on('update-downloaded', (info) => {
      log.info({update: info}, 'Update downloaded. Exit and install...')
      autoUpdater.quitAndInstall()
    })

    super(...opts)
  }

  clearTimeoutIfAny () {
    if (this.timeout) {
      clearTimeout(this.timeout)
      this.timeout = null<commit_msg>gui: Make sure electron-updater uses our logger<commit_after>const WindowManager = require('./window_manager')
const {autoUpdater} = require('electron-updater')

const log = require('cozy-desktop').default.logger({
  component: 'GUI:autoupdater'
})

const UPDATE_CHECK_TIMEOUT = 5000

module.exports = class UpdaterWM extends WindowManager {
  windowOptions () {
    return {
      title: 'UPDATER',
      width: 500,
      height: 400
    }
  }

  constructor (...opts) {
    autoUpdater.logger = log
    autoUpdater.on('update-available', (info) => {
      this.clearTimeoutIfAny()
      log.info({update: info, skipped: this.skipped}, 'Update available')
      // Make sure UI don't show up in front of onboarding after timeout
      if (!this.skipped) this.show()
    })
    autoUpdater.on('update-not-available', (info) => {
      log.info({update: info}, 'No update available')
      this.afterUpToDate()
    })
    autoUpdater.on('error', (err) => {
      log.error({err}, 'Error in auto-updater! ')
      // May happen in dev because of code signature error. Not really an issue.
      this.afterUpToDate()
    })
    autoUpdater.on('download-progress', (progressObj) => {
      log.trace({progress: progressObj}, 'Downloading...')
      this.send('update-downloading', progressObj)
    })
    autoUpdater.on('update-downloaded', (info) => {
      log.info({update: info}, 'Update downloaded. Exit and install...')
      autoUpdater.quitAndInstall()
    })

    super(...opts)
  }

  clearTimeoutIfAny () {
    if (this.timeout) {
      clearTimeout(this.timeout)
      this.timeout = null
{'fraction_non_alphanumeric': 0.14755669115298628, 'fraction_numerical': 0.0063877355477483235, 'mean_word_length': 3.078125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '495727', 'n_tokens_mistral': 992, 'n_tokens_neox': 969, 'n_words': 217}