3

I am implementing autoupdate in my Electron app using squirrel. When the updates are downloaded I show the user a dialog giving them two options:

  1. Quit the app and install the update immediately (using autoUpdater.quitAndInstall())
  2. Temporarily set aside the update and install it the next time the app starts

Option 1 - quite and install now works fine, but I cannot get option 2 - install at next app launch - to work.

The desired behaviour is that if the user chooses to install later, the update is installed immediately the next time the app is launched.

In my app, I handle the autoUpdater update-downloaded event. I also called checkForUpdates when the app starts. I assumed that if the update was ignored, then when the app is next launched the call to checkForUpdates would cause squirrel to notice the existing download, emit the update-downloaded event and the user would get asked again whether they want to install the update. However, no update-downloaded event is emitted.

Second, if the user selects install later, I wrote a flag to a userData file telling the app to call autoUpdater.quitAndInstall the next time the app launched. This gives an error since this method can only be called after update-downloaded has been emitted.

So how can I get this to work? Do I need to somehow delete the existing download so it is downloaded again when the app is next launched? This doesn't seem right.

Mike Goodwin
  • 8,810
  • 2
  • 35
  • 50

1 Answers1

0

Call autoUpdater.checkForUpdates(); when the app launches like this:

autoUpdater.addListener("update-downloaded", function () {
    if (userData flag) {
        autoUpdater.quitAndInstall();
    }
});

autoUpdater.setFeedURL('autoUpdaterFeedUrl');
autoUpdater.checkForUpdates();
Joshua
  • 5,032
  • 2
  • 29
  • 45
  • 2
    It looks like the update will still get installed whenever the user quits. It seems that `autoUpdate.checkForUpdates()` does more than check - it also initiates the download, and queues up the download to install no matter what. I think what Mike Goodwin wants is to be able to prevent the update until such time as the user explicitly agrees to it. – GladstoneKeep Jun 01 '17 at 13:54
  • @GladstoneKeep is correct. I will edit the question to make it more clear. – Mike Goodwin Jun 01 '17 at 19:23