22const url = require ( 'url' ) ;
33const path = require ( 'path' ) ;
44const electron = require ( 'electron' ) ;
5+ const { autoUpdater} = require ( 'electron-updater' ) ;
56
67// Module to control application life.
78const app = electron . app ;
@@ -13,6 +14,9 @@ const BrowserWindow = electron.BrowserWindow;
1314let mainWindow ;
1415
1516function createWindow ( ) {
17+ // trigger autoupdate check
18+ autoUpdater . checkForUpdates ( ) ;
19+
1620 // Create the browser window.
1721 mainWindow = new BrowserWindow ( {
1822 width : 800 ,
@@ -62,5 +66,33 @@ app.on('activate', function() {
6266 }
6367} ) ;
6468
65- // In this file you can include the rest of your app's specific main process
66- // code. You can also put them in separate files and require them here.
69+ //-------------------------------------------------------------------
70+ // Auto updates
71+ //-------------------------------------------------------------------
72+ autoUpdater . on ( 'checking-for-update' , ( ) => {
73+ console . log ( 'Checking for update...' ) ;
74+ } ) ;
75+ autoUpdater . on ( 'update-available' , info => {
76+ console . log ( 'Update available.' ) ;
77+ } ) ;
78+ autoUpdater . on ( 'update-not-available' , info => {
79+ console . log ( 'Update not available.' ) ;
80+ } ) ;
81+ autoUpdater . on ( 'error' , err => {
82+ console . log ( 'Error in auto-updater.' ) ;
83+ } ) ;
84+ autoUpdater . on ( 'download-progress' , progressObj => {
85+ console . log (
86+ `Download speed: ${ progressObj . bytesPerSecond } - Downloaded ${ progressObj . percent } % (${ progressObj . transferred } + '/' + ${ progressObj . total } + )`
87+ ) ;
88+ } ) ;
89+ autoUpdater . on ( 'update-downloaded' , info => {
90+ console . log ( 'Update downloaded; will install now' ) ;
91+ } ) ;
92+
93+ autoUpdater . on ( 'update-downloaded' , info => {
94+ // Wait 5 seconds, then quit and install
95+ // In your application, you don't need to wait 500 ms.
96+ // You could call autoUpdater.quitAndInstall(); immediately
97+ autoUpdater . quitAndInstall ( ) ;
98+ } ) ;
0 commit comments