Electron autoupdater progress bar
Asked Answered
N

2

9

is there any way to set up a progress bar for downloading new update of app in Electron? I am developing app for Windows using Squirrel and electron-simple-updater and my problem is that updater only gives out events when it starts to download update and when it finishes. My update is kinda large (around 80MB) and for users with slow ISPs it kinda sux :(

Nitre answered 10/1, 2017 at 12:17 Comment(4)
Looking for the same, google is not helping ...Fulcher
Same here...the 'download-progress' is not fired using electron-simple-updater. Did you manage to find a workaround?Consternation
@Consternation nope, I am stuck here. Its really bad that if you need this simple thing you have to do all the work yourself meaning building your own updater. Thats where maybe I will end up, because there seems to be no viable solutions for this problem :(Nitre
Actually I'm not even able to download the update. I'm getting an error "Cannot find Squirrel". I'm also using electrin-simple-updater and creating my .exe with electron-builder. Any help you can give me?Consternation
E
6
const log = require('electron-log');
const { autoUpdater } = require("electron-updater");
autoUpdater.logger = log;
log.info('App starting...');    
autoUpdater.on('download-progress', (progressObj) => {
    let log_message = "Download speed: " + progressObj.bytesPerSecond;
    log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
    log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
    sendStatusToWindow(log_message);
})

function sendStatusToWindow(text) {
    log.info(text);
    homePageWindow.webContents.send('message', text);
}

With this code the log can be seen to see the progress of the download

Electrodynamic answered 5/2, 2019 at 11:28 Comment(3)
NOTE: The package require("electron-updater") is strictly for Electron Builder, not for native Electron. If you are not using Electron Builder, you cannot import and use this package as shown here.Whorish
Is there any way I can get rid of all the decimals on progressObj.percent?Basidiomycete
Math.round(progressObj.percent)Ludicrous
F
4

Maybe this link gives what you want

https://github.com/iffy/electron-updater-example/blob/master/main.js

autoUpdater.on('download-progress', (ev, progressObj) => {
  sendStatusToWindow('Download progress...');
})
Fulcher answered 4/5, 2017 at 6:31 Comment(3)
its not using SquirrelOxytocin
Note, this doesn't appear to work with Electron's native autoUpdater: electronjs.org/docs/api/auto-updaterWhorish
@joshuapinter Correct, this is not for electron's auto-updater. It's most likely for Electron Builder's custom auto updater.Whorish

© 2022 - 2024 — McMap. All rights reserved.