question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows: auto update should remove binary after install/relaunch

See original GitHub issue
  • Version: 19.48.3
  • Target: Win32

This problem may be specific to NSIS.

After performing an auto-update, the AppData/Roaming directory contains the .exe that was used to perform the update. After each version update, a new binary continues to live there, increasing the “bloat” of the application significantly. There are methods for an app to “clean up” after an update and delete these files, but this seems like it should be default behavior for the updater.

image 1

Here’s my package.json (with some redactions):

{
  "name": "wildlink",
  "productName": "Wildlink",
  "description": "foo",
  "version": "1.2.8",
  "main": "./app/main.js",
  "license": "UNLICENSED",
  "author": "Wildfire Systems, Inc. <info@wildlink.me>",
  "homepage": "https://wildlink.me",
  "scripts": {
    "start": "electron . --enable-logging",
    "testmacpartner": "electron . --enabled-logging -channel=$channelID",
    "dev": "NODE_ENV='development' ELECTRON_ENABLE_STACK_DUMPING=true ELECTRON_ENABLE_LOGGING=true npm run start",
    "postinstall": "electron-builder install-app-deps",
    "pack": "build --dir",
    "build:linux": "build --linux",
    "build:win": "build --win",
    "build:mac": "build --dmg",
    "build:all": "build --linux --win",
    "dist": "build"
  },
  "build": {
    "appId": "wildlink",
    "publish": [
      {
        "provider": "generic",
        "url": "https://wildlink.me/desktop-update"
      }
    ],
    "dmg": {
      "internetEnabled": true,
      "background": "./build/background.png",
      "iconSize": 85,
      "window": {
        "width": 417,
        "height": 213
      },
      "contents": [
        {
          "x": 106,
          "y": 84
        },
        {
          "x": 307,
          "y": 84,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "linux": {
      "target": [
        "deb"
      ],
      "category": "Utility"
    },
    "win": {
      "target": {
        "target": "NSIS",
        "arch": [
          "ia32"
        ]
      },
      "icon": "build/icon.ico"
    }
  },
  "repository": {
    "type": "git",
    "url": "xxx"
  },
  "bugs": {
    "url": "xxx"
  },
  "devDependencies": {
    "electron": "^1.8.4",
    "electron-builder": "19.48.3",
    "electron-packager": "^7.3.0",
    "electron-reload": "^1.2.2",
    "electron-toolkit": "^1.0.24",
    "electron-winstaller": "^2.6.4"
  },
  "dependencies": {
    "chart.js": "^2.7.2",
    "crypto-js": "^3.1.9-1",
    "electron-contextmenu-middleware": "^1.0.3",
    "electron-input-menu": "^2.1.0",
    "electron-json-storage": "^4.1.0",
    "electron-log": "^2.2.14",
    "electron-push-receiver": "^1.2.4",
    "electron-updater": "2.21.6",
    "first-run": "1.2.0",
    "localforage": "^1.7.1",
    "path": "^0.12.7",
    "request": "^2.85.0",
    "universal-analytics": "^0.4.16",
    "utf8": "^2.1.2",
    "winreg": "^1.2.4"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
develarcommented, Jul 31, 2018
  1. file __installer.exe is always in your app data.
  2. dir __update__ till first update check that returns “no available update”.
  3. old files from previous releases with bug are not deleted (I mean 1.1.43 version and other on your screenshot). It can be done via custom macro on uninstall if need. Or you can ask me if to provide some example if this issue is a problem for you.
2reactions
developeryashrajcommented, Jun 13, 2018

@CydeSwype Until electron builder comes with some inbuilt solution. We can do below code in our application. I have achieved this as below.

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
            }
        }
    }
}

Note :- Currently above code removes only latest downloaded installer. All previous installers are not being removed if more than one installer has been downloaded. For Ex:- if your app is running on 1.0.0. You release new version 1.2.0 then it will be downloaded. It may or may not install instantly as per your configuration. Now suppose that new update is not installed and you release new version 1.4.0 then 1.4.0 will be downloaded. Now if you install 1.4.0 then installer-1.4.0 will be removed after installation but installer-1.2.0 will remain as it is. You can remove that as well by keeping every downloaded installer information as array in JSON and can loop thorugh it under creatwindow().

Hope this solve your issue 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install multiple Windows updates or hotfixes with only ...
To install multiple updates with only one restart · Run the update installer with the -z switch to instruct the installer not to...
Read more >
Policy CSP - Update - Windows Client Management
1: Auto install the update and then notify the user to schedule a device restart. Updates are downloaded automatically on non-metered networks ...
Read more >
Step 4 - Configure Group Policy Settings for Automatic Updates
Specifies whether Automatic Updates will automatically install updates that don't interrupt Windows services or restart Windows.
Read more >
Manage device restarts after updates (Windows 10)
Registry keys used to manage restart · 1: enable automatic reboot after update installation at a scheduled time · 2: notify for download...
Read more >
How to stop automatic updates on Windows 10
You do not need to disable Windows Update permanently if you want to prevent the system from downloading a specific update immediately. Instead, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found