import { autoUpdater } from 'electron-updater' ; import { EventEmitter } from 'events' ; class CheckUpdate extends EventEmitter { constructor ( ) { super ( ) ; } init ( event ) { const message = { appName : 'CloudDisk' , error : '检查更新出错, 请联系开发人员' , checking : '正在检查更新……' , updateAva : '检测到新版本，正在下载……' , updateNotAva : '现在使用的就是最新版本，不用更新' , downloaded : '最新版本已下载，点击安装进行更新' , } ; autoUpdater . on ( 'checking-for-update' , function ( ) { event . sender . send ( 'check-for-update' , message . checking ) ; } ) ; autoUpdater . on ( 'update-available' , function ( info ) { event . sender . send ( 'update-down-success' , info ) ; event . sender . send ( 'check-for-update' , message . updateAva ) ; } ) ; autoUpdater . on ( 'update-not-available' , function ( ) { event . sender . send ( 'check-for-update' , message . updateNotAva ) ; } ) ; autoUpdater . on ( 'error' , function ( ) { event . sender . send ( 'check-for-update' , message . error ) ; } ) ; autoUpdater . on ( 'download-progress' , ( progressObj ) => { event . sender . send ( 'download-progress' , progressObj ) ; } ) ; autoUpdater . on ( 'update-downloaded' , function ( ) { event . sender . send ( 'check-for-update' , message . downloaded ) ; } ) ; } check ( event , data ) { autoUpdater . setFeedURL ( data ) ; this . init ( event ) ; autoUpdater . checkForUpdates ( ) ; } update ( ) { autoUpdater . quitAndInstall ( ) ; } } export default CheckUpdate ;