0
votes

I am using electron-builder and electron-updater way to update my application.

Scenario: My application checks for update within a minute when it starts. After that, it checks for update every 5 hours. I am not forcing my users to install the application when a new update is downloaded. Instead Installing of updated app will start at the time of app quit. I am just showing them that "a new update is available" with "Install now" button so that they can update it if they want ( using quitAndInstall) or when they quit app or during next start.

Now below are some queries related to electron-updater.

  • I notice that build downloads every time. Let's say if an update is available then downloading of new update will start in a minute when an app opens. Now a new app is not installed so after 5 hours it will again check for new update. Versions will be mismatched and so it starts downloading updates again even if it has downloaded already. Is this a default behavior or I am missing something? How can I stop this happening? It uses and affects both my Client's Data and My AWS bandwidth!

  • When an update is downloaded. After user updates the app, it's installer is still available and not removed. (Ex:- running on version 1.0.0, an update of 2.0.0 is available and downloaded, triggered quitAndInstall and updated the app. The installer-2.0.0.exe is still there after installation). Is this a default behavior? Does it(or windows) remove this downloaded files after some days?

I have searched regarding this thing but no luck till now!! Below are some version details.

electron : 2.0.2, electron-builder : 20.15.1 and electron-updater : 2.21.10

1

1 Answers

0
votes

Both issue has been resolved in electron-builder: 2.17.0 and electron-updater: 2.23.0

After debugging so much in code. I found a solution to both of my problems.

Problem: Multiple Download

(Solved in electron-builder: 2.16.0)

Old Solution

I found that electron-updater:2.21.10 already have a code to stop downloading again if that installer has been downloaded. But somehow comparing objects of fileinfo using lodash is not working and it creates an issue. So until we get any proper solution in a new version. I have changed below code.

File:- ..\node_modules\electron-updater\out\DownloadedUpdateHelper.js

return (0, _lodash().default)(_this.versionInfo, versionInfo) && (0, _lodash().default)(_this.fileInfo, fileInfo) && (yield (0, _fsExtraP().pathExists)(updateFile));

Just change (_this.fileInfo, fileInfo) to (_this.fileInfo.info, fileInfo.info). Detailed information is available here :- https://github.com/electron-userland/electron-builder/issues/3003

Note:- (I know changing node_modules is not a good way but this is all that I can do currently to keep the show going on. I have also submitted PR for the same so all I am waiting is for a proper solution)

Update:- PR accepted in electron-builder: 2.16.0


Problem: Removing installer

(Solved in electron-builder: 2.17.0, check for issue #3000)

Old Solution

I found that there is no any inbuilt solution to remove installer as of now so I have created my own to handle it. It can be achieved by

Step 1:- Save file path and version of the newly downloaded file to DB or somewhere in a file as JSON Object.

autoUpdater.on('update-downloaded', async (event) => {
    console.log("update-downloaded");
    let download_exe_obj = {path: autoUpdater.downloadedUpdateHelper._file, version: event.version};
    await update_downloaded_exe_data(download_exe_obj);// save download_exe_obj somewhere so that it can be used later on
});

Step 2:- Check current app version with the saved JSON when app starts (createWindow). If we found app version same as version saved in json then we can remove previously downloaded installer as that installer is already installed.

const app = electron.app; //to get version and details from package.json
function createWindow() {
    mainWindow = new BrowserWindow({ width: 800, height: 600 })
    ...
    let available_exe_json = await get_downloaded_exe_data(); //get json from where you have saved
    if(available_exe_json != ''){
        let available_exe_obj = JSON.parse(available_exe_json);
        if (available_exe_obj.version != '' && available_exe_obj.version.toString() == app.getVersion().toString()) {
            //remove old installer
            if (available_exe_obj.path != '' && await fs.existsSync(available_exe_obj.path)) {
              await fs.unlinkSync(available_exe_obj.path);
              await update_downloaded_exe_data('');//update with blank where you have saved previous data
            }
        }
    }
}

We can also manage to remove multiple installers. More details regarding this solution can be found here:- https://github.com/electron-userland/electron-builder/issues/3000#issuecomment-396833579