{"size": 1383, "ext": "js", "max_stars_repo_path": "src/main/autoupdate.js", "max_stars_repo_name": "DerekZiemba/astrofox", "max_stars_repo_stars_event_min_datetime": "2020-10-07T04:37:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T00:56:49.000Z", "max_issues_repo_path": "src/main/autoupdate.js", "max_issues_repo_name": "DerekZiemba/astrofox", "max_issues_repo_issues_event_min_datetime": "2020-10-07T16:10:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T14:05:48.000Z", "max_forks_repo_path": "src/main/autoupdate.js", "max_forks_repo_name": "DerekZiemba/astrofox", "max_forks_repo_forks_event_min_datetime": "2020-10-07T09:25:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T09:53:07.000Z"}
{"max_stars_count": 1020, "max_issues_count": 39, "max_forks_count": 67, "avg_line_length": 23.4406779661, "max_line_length": 60, "alphanum_fraction": 0.6507592191}
import { ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import debug from 'debug';
import { sendMessage } from './window';
import { USER_AGENT } from './environment';

const log = debug('autoupdate');

export default function init() {
  autoUpdater.autoDownload = false;
  autoUpdater.requestHeaders = { 'User-Agent': USER_AGENT };

  autoUpdater.on('error', error => {
    log('update-error');

    sendMessage('update-error', error);
  });

  autoUpdater.on('checking-for-update', () => {
    log('checking-for-update');
  });

  autoUpdater.on('update-available', info => {
    log('update-available');

    sendMessage('update-available', info);
  });

  autoUpdater.on('update-not-available', info => {
    log('update-not-available');

    sendMessage('update-not-available', info);
  });

  autoUpdater.on('download-progress', progress => {
    log('download-progress', progress);

    sendMessage('download-progress', progress);
  });

  autoUpdater.on('update-downloaded', info => {
    log('update-downloaded');

    sendMessage('update-downloaded', info);
  });

  ipcMain.handle('check-for-updates', () => {
    return autoUpdater.checkForUpdates();
  });

  ipcMain.handle('download-update', () => {
    return autoUpdater.downloadUpdate();
  });

  ipcMain.handle('quit-and-install', () => {
    return autoUpdater.quitAndInstall();
  });
}
