2
2
const url = require ( 'url' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const electron = require ( 'electron' ) ;
5
+ const { autoUpdater} = require ( 'electron-updater' ) ;
5
6
6
7
// Module to control application life.
7
8
const app = electron . app ;
@@ -13,6 +14,9 @@ const BrowserWindow = electron.BrowserWindow;
13
14
let mainWindow ;
14
15
15
16
function createWindow ( ) {
17
+ // trigger autoupdate check
18
+ autoUpdater . checkForUpdates ( ) ;
19
+
16
20
// Create the browser window.
17
21
mainWindow = new BrowserWindow ( {
18
22
width : 800 ,
@@ -62,5 +66,33 @@ app.on('activate', function() {
62
66
}
63
67
} ) ;
64
68
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