1
1
// Modules to control application life and create native browser window
2
2
const { app, BrowserWindow} = require ( 'electron' )
3
3
4
+ const { autoUpdater} = require ( 'electron-updater' ) ;
5
+ const log = require ( 'electron-log' ) ;
6
+ autoUpdater . logger = log ;
7
+ autoUpdater . logger . transports . file . level = 'info' ;
8
+ log . info ( 'App starting...' ) ;
9
+
4
10
5
11
// Keep a global reference of the window object, if you don't, the window will
6
12
// be closed automatically when the JavaScript object is garbage collected.
@@ -28,6 +34,11 @@ function createWindow () {
28
34
} )
29
35
}
30
36
37
+ function sendStatusToWindow ( text ) {
38
+ log . info ( text ) ;
39
+ mainWindow . webContents . send ( 'message' , text ) ;
40
+ }
41
+
31
42
var shouldQuit = app . makeSingleInstance ( function ( commandLine , workingDirectory ) {
32
43
// Someone tried to run a second instance, we should focus our window.
33
44
if ( mainWindow ) {
@@ -44,7 +55,10 @@ return;
44
55
// This method will be called when Electron has finished
45
56
// initialization and is ready to create browser windows.
46
57
// Some APIs can only be used after this event occurs.
47
- app . on ( 'ready' , createWindow )
58
+ app . on ( 'ready' , ( ) => {
59
+ createWindow ( ) ;
60
+ autoUpdater . checkForUpdatesAndNotify ( ) ;
61
+ } )
48
62
49
63
// Quit when all windows are closed.
50
64
app . on ( 'window-all-closed' , function ( ) {
@@ -66,6 +80,29 @@ app.on('activate', function () {
66
80
// In this file you can include the rest of your app's specific main process
67
81
// code. You can also put them in separate files and require them here.
68
82
83
+
84
+ autoUpdater . on ( 'checking-for-update' , ( ) => {
85
+ sendStatusToWindow ( 'Checking for update...' ) ;
86
+ } )
87
+ autoUpdater . on ( 'update-available' , ( info ) => {
88
+ sendStatusToWindow ( 'Update available.' ) ;
89
+ } )
90
+ autoUpdater . on ( 'update-not-available' , ( info ) => {
91
+ sendStatusToWindow ( 'Update not available.' ) ;
92
+ } )
93
+ autoUpdater . on ( 'error' , ( err ) => {
94
+ sendStatusToWindow ( 'Error in auto-updater. ' + err ) ;
95
+ } )
96
+ autoUpdater . on ( 'download-progress' , ( progressObj ) => {
97
+ let log_message = "Download speed: " + progressObj . bytesPerSecond ;
98
+ log_message = log_message + ' - Downloaded ' + progressObj . percent + '%' ;
99
+ log_message = log_message + ' (' + progressObj . transferred + "/" + progressObj . total + ')' ;
100
+ sendStatusToWindow ( log_message ) ;
101
+ } )
102
+ autoUpdater . on ( 'update-downloaded' , ( info ) => {
103
+ sendStatusToWindow ( 'Update downloaded' ) ;
104
+ autoUpdater . quitAndInstall ( ) ;
105
+ } ) ;
69
106
//------------------------------------------------------------//
70
107
const appVersion = require ( './package.json' ) . version ;
71
108
const { ipcMain} = require ( 'electron' ) ;
0 commit comments