import { app , dialog } from 'electron' ; import { autoUpdater } from 'electron-updater' ; import App from '../app' ; export default class UpdateEvents { static initAutoUpdateService ( ) { if ( ! App . isDevelopmentMode ( ) ) { console . log ( 'Initializing auto update service...\n' ) ; UpdateEvents . checkForUpdates ( ) ; } } static checkForUpdates ( ) { if ( ! App . isDevelopmentMode ( ) && autoUpdater . getFeedURL ( ) !== '' ) { autoUpdater . checkForUpdates ( ) ; } } } autoUpdater . on ( 'update-downloaded' , ( event , releaseNotes , releaseName , releaseDate ) => { const dialogOpts = { type : 'info' , buttons : [ 'Restart' , 'Later' ] , title : 'Application Update' , message : process . platform === 'win32' ? releaseNotes : releaseName , detail : 'A new version has been downloaded. Restart the application to apply the updates.' } ; dialog . showMessageBox ( dialogOpts ) . then ( returnValue => { if ( returnValue . response === 0 ) autoUpdater . quitAndInstall ( ) ; } ) ; } ) ; autoUpdater . on ( 'checking-for-update' , ( ) => { console . log ( 'Checking for updates...\n' ) ; } ) ; autoUpdater . on ( 'update-available' , ( ) => { console . log ( 'New update available!\n' ) ; } ) ; autoUpdater . on ( 'update-not-available' , ( ) => { console . log ( 'Up to date!\n' ) ; } ) ; autoUpdater . on ( 'before-quit-for-update' , ( ) => { console . log ( 'Application update is about to begin...\n' ) ; } ) ; autoUpdater . on ( 'error' , message => { console . error ( 'There was a problem updating the application' ) ; console . error ( message , '\n' ) ; } ) ;