@@ -3,6 +3,12 @@ const url = require('url');
33const path = require ( 'path' ) ;
44const electron = require ( 'electron' ) ;
55const { autoUpdater} = require ( 'electron-updater' ) ;
6+ const log = require ( 'electron-log' ) ;
7+
8+ // configure logging
9+ autoUpdater . logger = log ;
10+ autoUpdater . logger . transports . file . level = 'info' ;
11+ log . info ( 'App starting...' ) ;
612
713// Module to control application life.
814const app = electron . app ;
@@ -14,9 +20,6 @@ const BrowserWindow = electron.BrowserWindow;
1420let mainWindow ;
1521
1622function createWindow ( ) {
17- // trigger autoupdate check
18- autoUpdater . checkForUpdates ( ) ;
19-
2023 // Create the browser window.
2124 mainWindow = new BrowserWindow ( {
2225 width : 800 ,
@@ -33,7 +36,7 @@ function createWindow() {
3336 ) ;
3437
3538 // Open the DevTools.
36- // mainWindow.webContents.openDevTools();
39+ mainWindow . webContents . openDevTools ( ) ;
3740
3841 // Emitted when the window is closed.
3942 mainWindow . on ( 'closed' , function ( ) {
@@ -42,6 +45,9 @@ function createWindow() {
4245 // when you should delete the corresponding element.
4346 mainWindow = null ;
4447 } ) ;
48+
49+ // trigger autoupdate check
50+ autoUpdater . checkForUpdates ( ) ;
4551}
4652
4753// This method will be called when Electron has finished
@@ -69,25 +75,32 @@ app.on('activate', function() {
6975//-------------------------------------------------------------------
7076// Auto updates
7177//-------------------------------------------------------------------
78+ const sendStatusToWindow = ( text ) => {
79+ log . info ( text ) ;
80+ if ( mainWindow ) {
81+ mainWindow . webContents . send ( 'message' , text ) ;
82+ }
83+ } ;
84+
7285autoUpdater . on ( 'checking-for-update' , ( ) => {
73- console . log ( 'Checking for update...' ) ;
86+ sendStatusToWindow ( 'Checking for update...' ) ;
7487} ) ;
7588autoUpdater . on ( 'update-available' , info => {
76- console . log ( 'Update available.' ) ;
89+ sendStatusToWindow ( 'Update available.' ) ;
7790} ) ;
7891autoUpdater . on ( 'update-not-available' , info => {
79- console . log ( 'Update not available.' ) ;
92+ sendStatusToWindow ( 'Update not available.' ) ;
8093} ) ;
8194autoUpdater . on ( 'error' , err => {
82- console . log ( ' Error in auto-updater.' ) ;
95+ sendStatusToWindow ( ` Error in auto-updater: ${ err . toString ( ) } ` ) ;
8396} ) ;
8497autoUpdater . on ( 'download-progress' , progressObj => {
85- console . log (
98+ sendStatusToWindow (
8699 `Download speed: ${ progressObj . bytesPerSecond } - Downloaded ${ progressObj . percent } % (${ progressObj . transferred } + '/' + ${ progressObj . total } + )`
87100 ) ;
88101} ) ;
89102autoUpdater . on ( 'update-downloaded' , info => {
90- console . log ( 'Update downloaded; will install now' ) ;
103+ sendStatusToWindow ( 'Update downloaded; will install now' ) ;
91104} ) ;
92105
93106autoUpdater . on ( 'update-downloaded' , info => {
0 commit comments