diff --git a/main.js b/main.js index 3fdb5b7..cfaef91 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ const electron = require('electron') // Module to control application life. const { app, BrowserWindow } = electron +// IF you want to enable automatic update uncomment the line below const updater = require('./updater') // Keep window state @@ -84,15 +85,12 @@ if (process.platform === 'darwin') { const menu = electron.Menu.buildFromTemplate(template) - - function createWindow() { let winState = windowStateKeeper({ defaultWidth: 900, defaultHeight: 600 }) - // electron.Menu.setApplicationMenu(menu) electron.Menu.setApplicationMenu(null) // Create the browser window. @@ -137,6 +135,7 @@ function createWindow() { require('electron').shell.openExternal(url); }); + // IF you want to enable automatic update uncomment the line below setTimeout(updater.check, 2000); } diff --git a/renderer/progress.html b/renderer/progress.html index 433f094..0868974 100644 --- a/renderer/progress.html +++ b/renderer/progress.html @@ -5,6 +5,13 @@ Downloading PIA Update - Download in progress... + + diff --git a/updater.js b/updater.js index 823c765..ef449a6 100644 --- a/updater.js +++ b/updater.js @@ -1,4 +1,4 @@ -const {dialog, BrowserWindow} = require('electron') +const {dialog, BrowserWindow, ipcMain} = require('electron') const {autoUpdater} = require('electron-updater') const path = require('path') @@ -14,6 +14,8 @@ exports.check = () => { autoUpdater.on('update-available', () => { + let downloadProgress = 0 + dialog.showMessageBox({ type: 'info', title: 'Update Available', @@ -45,6 +47,15 @@ exports.check = () => { progressWin = null }) + ipcMain.on('download-progress-request', (e) => { + e.returnValue = downloadProgress + }) + + autoUpdater.on('download-progress', (d) => { + console.log(d.percent); + downloadProgress = d.percent + }) + autoUpdater.on('update-downloaded', () => { if (progressWin) progressWin.close() dialog.showMessageBox({