Electron-builder: NSIS with oneClick set to true does not relaunch the app after update

Created on 5 Nov 2016  Â·  13Comments  Â·  Source: electron-userland/electron-builder

  • Version: 7.21.0

  • Target: Windows NSIS

Description of the problem: Windows NSIS with oneClick set to true does not relaunch the app after update (using quitAndInstall). On the other hand, using the same build for OSX (Squirrel.Mac) it relaunches the app after updating (using the same code of quitAndInstall). This confuses the customer as there is no installergif or validation that the update is done.

Configuration looks like:

"build": {
    "appId": X
    "asar": false,
    "category": X
    "win": {
      "target": "nsis"
     },
     "nsis": {
      "guid": X,
      "oneClick": true
    }
electron-updater feature nsis

Most helpful comment

I wasn't going to be picky, but the install update showing progress would be great! An installer gif or a progress bar (similar to a normal install) would be awesome.

All 13 comments

macOS also doesn't relaunch app — update silently installed on quit. Are you sure?

It does for me. Is it not supposed to relaunch the app after the update? I will post some of our updating code then.

I don't think we are doing anything special below.

We have IPC handlers that are promises and check for updates on init. If an update is found: A modal pops up, silently downloads, then quits, removes old, installs new app, then boots it back up on Mac. Using electron-release-server for squirrel.Mac and an S3 bucket as the generic provider for windows.

import { autoUpdater } from 'electron-auto-updater'; 
import ....;
/**
 * Initializes the autoUpdater event functions and feedURL
 */
export function updateInit() {
  autoUpdater.on('update-available', function(event) {
    logger.log(`Update available ${JSON.stringify(event)}`);
  });

  autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateURL) {
    logger.log(`Update downloaded ${JSON.stringify(event)}`);
    autoUpdater.quitAndInstall();
  });

  autoUpdater.on('error', function(error, msg) {
    logger.error(`Update error ${JSON.stringify(error)}`);
    logger.error(`Update error ${JSON.stringify(msg)}`);
  });

  autoUpdater.on('checking-for-update', function(event) {
    logger.log(`Checking-for-update ${JSON.stringify(event)}`);
  });

  autoUpdater.on('update-not-available', function(event) {
    logger.log(`Update not available ${JSON.stringify(event)}`);
  });
  if (os === 'darwin') {
    let feedurl = `${releaseServer}/update/${os}/${appVersion}`;
    autoUpdater.setFeedURL(feedurl);
  }
}


/**
 * Uses the autoUpdater to checkForUpdates. Has a timeout of ten seconds
 * @return {Boolean}        whether or not there is an update available
 */
export const checkForUpdate = () => {
  return new Promise(async (resolve, reject) => {
    try {
      if (os === 'darwin') {
        autoUpdater.setFeedURL(`${releaseServer}/update/${os}/${appVersion}`);
      }
      autoUpdater.checkForUpdates();
      // Safety check the event and resolve true if an update is available
      autoUpdater.on('update-available', function(event) {
        logger.log(`Update available ${JSON.stringify(event)}`);
        return resolve(true);
      });
      // Safety check the event and resolve false if an update is not available
      autoUpdater.on('update-not-available', function(event) {
        logger.log(`Update not available ${JSON.stringify(event)}`);
        return resolve(false);
      });
      // Set a timeout for finding the update in case the server does not respond
      setTimeout(() => {
        return resolve(false);
      }, autoUpdateTimeoutMs);
    } catch (err) {
      logger.log(`Could not get update. ${err}`);
      return resolve(false);
    }
  });
};

In general, I don't recommend to call autoUpdater.quitAndInstall explicitly.

Please see https://github.com/develar/onshape-desktop-shell/blob/nsis/src/AppUpdater.ts

Why do you need to bother user? Just show notification (native) that "Version ${releaseName} is downloaded and will be automatically installed on Quit" and nothing else. Don't interrupt user work. Exactly as Google Chrome update works (even without notification, only toolbar icon has different colour).

Ok, ok, up to you. If you say that explicit quitAndInstall on macOs does relaunch — I will check and fix NSIS updater.

If you are unable to reproduce it and/or its too heavy to fix, I will look into the Google Chrome way and potentially remind people to quit the app so they can get the latest versions.

There are pros and cons to both, as you may know.

For example a pro of "interrupting" way would be:
People will always get the latest updates. It takes less than 3 minutes on mac and less than 5 minutes on windows.

An example of a con would be:
If people never close the application, they will never get the latest releases that have critical features or bug fixes. I've seen this in many situations (esp Google Chrome). People like to keep all their tabs open and multiple windows, therefore they never get the latest.

In our case, the application is more of a platform, and its okay to interrupt the customer because no data is lost or needed to be saved via our application.

All in all, I appreciate the guidance. Thanks!

You are right, thanks.

But in this case (explicit quitAndInstall), install of update should be not silent, right? Some progress should be reported — i.e. the same as in case of standard install.

I wasn't going to be picky, but the install update showing progress would be great! An installer gif or a progress bar (similar to a normal install) would be awesome.

Also, not sure if you know about this, but if you have the app on your taskbar on Windows and the app updates, the shortcut gets removed. It works fine on Mac, but I suspect that the NSIS updater deletes the shortcut when uninstalling the old app.

I have a similar need for an application that I am developing - where the application is open/active for a very long time and the user is not going to close and restart the application.
I've coded for an update check and then prompting the user that the update is available.

However, I am encountering the same issue whereby the autoUpdater.quitAndInstall() call does quit and update the application, however, it does not restart the application.

As an aside - I am also considering adding an update check silently and then presenting the user with a prompt that the application will be upgraded in X minutes with the option to 'dismiss' this instance of the update.

Naturally, I will need the auto-restart issue to work before I do this. Any ideas as to what may be causing this issue?

I found a similar issue raised several years ago by the looks of things. Not sure if it is relevant...

Fixed in electron-auto-updater 0.6.0.

Please note — currently, app will be relaunched only if you don't set runAfterFinish to false (defaults to true, if you didn't customise it, don't worry).

@pwdl I hope your issue is fixed as well.

@develar - do you know if this will fix @Jflinchum issue as well, or should that be a different issue? I notice similar behavior.

When you do auto-update, it installs it in a new folder, deletes the old folder, and leaves the dock icon referencing a folder that doesn't exist.

Example workflow:

### User side: 
1. user has electron app on Windows Dock.
2. User runs electron app on 2.0.21. It is installed in C:\Program Files\electron-app\2.0.21\electron-app.exe 
3. User boots up the app. 
4. User gets install prompt. Accepts it.
5. The app downloads. 
### Electron-App: 
* Creates a new folder 2.0.22. 
* Installs Electron-app in the  2.0.22. 
* Deletes folder 2.0.21.
* leaves the dock icon referencing a folder and .exe that doesn't exist.

@SxMShaDoW please file your comment as new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AidanNichol picture AidanNichol  Â·  3Comments

philcockfield picture philcockfield  Â·  3Comments

antonycourtney picture antonycourtney  Â·  3Comments

jhg picture jhg  Â·  3Comments

talarari picture talarari  Â·  3Comments