Skip to content

Commit

Permalink
Activated auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmas58 committed Jul 11, 2019
1 parent 2122643 commit 7b785ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 2 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 8 additions & 1 deletion renderer/progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<title>Downloading PIA Update</title>
</head>
<body>
Download in progress...
<progress style="width:100%;" value="0" max="100"></progress>
<script>
const {ipcRenderer} = require('electron')
setInterval(() => {
let progress = ipcRenderer.sendSync('download-progress-request')
document.querySelector('progress').value = progress
}, 1000)
</script>
</body>
</html>
13 changes: 12 additions & 1 deletion updater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {dialog, BrowserWindow} = require('electron')
const {dialog, BrowserWindow, ipcMain} = require('electron')
const {autoUpdater} = require('electron-updater')

const path = require('path')
Expand All @@ -14,6 +14,8 @@ exports.check = () => {

autoUpdater.on('update-available', () => {

let downloadProgress = 0

dialog.showMessageBox({
type: 'info',
title: 'Update Available',
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 7b785ea

Please sign in to comment.