|
1 | 1 | 'use strict'; |
2 | 2 | const electron = require('electron'); |
| 3 | +const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron'); |
3 | 4 |
|
4 | | -var fs = require('fs'); |
| 5 | +const log = require('electron-log'); |
| 6 | +const {autoUpdater} = require("electron-updater"); |
| 7 | + |
| 8 | +autoUpdater.logger = log; |
| 9 | +autoUpdater.logger.transports.file.level = 'info'; |
| 10 | +log.info('App starting...'); |
| 11 | + |
| 12 | +function sendStatusToWindow(text) { |
| 13 | + log.info(text); |
| 14 | + mainWindow.webContents.send('message', text); |
| 15 | +} |
| 16 | +autoUpdater.on('checking-for-update', () => { |
| 17 | + sendStatusToWindow('Checking for update...'); |
| 18 | +}) |
| 19 | +autoUpdater.on('update-available', (info) => { |
| 20 | + sendStatusToWindow('Update available.'); |
| 21 | +}) |
| 22 | +autoUpdater.on('update-not-available', (info) => { |
| 23 | + sendStatusToWindow('Update not available.'); |
| 24 | +}) |
| 25 | +autoUpdater.on('error', (err) => { |
| 26 | + sendStatusToWindow('Error in auto-updater. ' + err); |
| 27 | +}) |
| 28 | +autoUpdater.on('download-progress', (progressObj) => { |
| 29 | + let log_message = "Download speed: " + progressObj.bytesPerSecond; |
| 30 | + log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'; |
| 31 | + log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'; |
| 32 | + sendStatusToWindow(log_message); |
| 33 | +}) |
| 34 | +autoUpdater.on('update-downloaded', (info) => { |
| 35 | + sendStatusToWindow('Update downloaded'); |
| 36 | +}); |
5 | 37 |
|
6 | | -const app = electron.app; |
| 38 | +var fs = require('fs'); |
7 | 39 |
|
8 | 40 | // adds debug features like hotkeys for triggering dev tools and reload |
9 | 41 | require('electron-debug')(); |
@@ -43,6 +75,7 @@ app.on('activate', () => { |
43 | 75 |
|
44 | 76 | app.on('ready', () => { |
45 | 77 | mainWindow = createMainWindow(); |
| 78 | + autoUpdater.checkForUpdatesAndNotify(); |
46 | 79 | }); |
47 | 80 |
|
48 | 81 | const ipc = require('electron').ipcMain; |
|
0 commit comments