Auto-Update quitAndInstall Not Working On Mac

See original GitHub issue

“electron-builder”: “^18.2.1” “electron-updater”: “^1.16.0” Target: Mac

My auto-update on Windows is working fine. However I still have two issues on the Mac.

On the Mac it recognises that there is an update then asks the user if they want to download and install. If the user responds ‘Yes’ then the update is downloaded and the user is advised that the new version is downloaded and will be installed when they click OK. However the quitAndInstall never seems to get called. If I close the app and re-open it again it just goes through the same process. Also on Mac my progress is not logged to my log file, nor is the status bar working. Both of these things work correctly on Windows. See code and log file below.

log.txt

`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 + ‘)’; log.log(‘info’, log_message); mainWindow.setProgressBar((progressObj && progressObj.percent) ? progressObj.percent / 100 : -1) });

autoUpdater.on('update-downloaded', (versionInfo) => {
    var dialogOptions = {
        type: 'question',
        defaultId: 0,
        message: `The update is ready to install, Version ${versionInfo.version} has been downloaded and will be automatically installed when you click OK`
    };
    dialog.showMessageBox(mainWindow, dialogOptions, function() {
        if (!isDev) {
            autoUpdater.quitAndInstall();
        }
    });
});`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
develarcommented, Jun 7, 2017

It is not electron-updater issue. Please see https://github.com/electron/electron/issues/3583

As you have made a donation, issue was investigated by me for you.

You need to modify your code:

setImmediate(() => {
  app.removeAllListeners("window-all-closed")
  if (focusedWindow != null) {
    focusedWindow.close()
  }
  autoUpdater.quitAndInstall(false)
})
  1. In the your dialog handler, you must call quitAndInstall or other actions only in the setImmediate. To ensure that all dialog/sheet windows were released.
  2. To ensure that your window-all-closed handler (if it is added, e.g. https://github.com/develar/onshape-desktop-shell/blob/master/src/WindowManager.ts#L16) doesn’t prevent quit, remove all such listeners app.removeAllListeners("window-all-closed").
  3. Explicitly close window. mainWindow.close() If you have more than one windows, close all (BrowserWindow.getAllWindows() to get all windows).

If still no luck — try mainWindow.destroy().

Don’t forget to update to electron-updater 2.1.1

13reactions
onassarcommented, Mar 11, 2018

I (quite naturally) had a close event on a BrowserWindow set up (for Macs) in order to capture the Command+W hotkey. Because of this, the autoUpdater.quitAndInstall method wasn’t working. Here’s my go at a helper-function to deal with cases of aggressive event listeners preventing the app from properly restarting:

/**
 * ensureSafeQuitAndInstall
 * 
 * @access  public
 * @return  void
 */
function ensureSafeQuitAndInstall() {
    const electron = require('electron');
    const app = electron.app;
    const BrowserWindow = electron.BrowserWindow;
    app.removeAllListeners('window-all-closed');
    var browserWindows = BrowserWindow.getAllWindows();
    browserWindows.forEach(function(browserWindow) {
        browserWindow.removeAllListeners('close');
    });
}

Hope this is helpful to someone out there 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

electron auto updater not installing in OSx - Stack Overflow
When the user click on "Quit and Install" which calls autoUpdater.quitAndInstall() the app does not actually close (still appear as open in the ......
Read more >
autoUpdater | Electron
Unter MacOS basiert das autoUpdater Modul auf Squirrel. ... Dieses Event wird ausgelöst, wenn die Funktion quitAndInstall() aufgerufen wird. Das before-quit ...
Read more >
How to use the electron-updater.autoUpdater.quitAndInstall ...
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
AutoUpdater dont work : r/electronjs - Reddit
Mac, pipe /Users/lucaslomeu/Library/Application ... PRuYi8h/ElecUp.app/ did not pass validation: code has no ... My script doesnt work.
Read more >
autoUpdater | Electron
Under the hood calling autoUpdater.quitAndInstall() will close all application windows first, and automatically call app.quit() after all windows have been ...
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