Added auto-update download progress bar

This commit is contained in:
Joel Collins 2020-03-30 12:16:32 +01:00
parent 3c32dab014
commit 5fb1a887d9
3 changed files with 45 additions and 4 deletions

View file

@ -4,6 +4,7 @@ const { dialog } = require("electron");
const updater = require("electron-updater");
const autoUpdater = updater.autoUpdater;
const contextMenu = require("electron-context-menu");
const ProgressBar = require("electron-progressbar");
const path = require("path");
// Attach settings store
@ -26,12 +27,44 @@ autoUpdater.on("update-available", function(info) {
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
console.log("Downloading update selected");
handleDownloadUpdate();
}
}
);
});
// Download, with a progress bar
function handleDownloadUpdate() {
console.log("Downloading update");
var progressBar = new ProgressBar({
indeterminate: false,
text: "Downloading update...",
detail: "Please wait...",
browserWindow: {
webPreferences: {
nodeIntegration: true
}
}
});
progressBar.on("ready", function() {
autoUpdater.on("download-progress", function(info) {
progressBar.value = info.percent;
progressBar.detail = `${Math.floor(info.percent)}% ${info.bytesPerSecond /
1000}kb/s`;
});
autoUpdater.on("update-downloaded", function() {
progressBar.close();
});
autoUpdater.on("error", function() {
progressBar.close();
});
autoUpdater.downloadUpdate();
});
}
// Trigger update installation
autoUpdater.on("update-downloaded", function(info) {
sendStatusToWindow("Update downloaded." + info);
dialog.showMessageBox(