Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Update quitAndInstall Not Working On Mac #1604

Closed
daveywc opened this issue May 31, 2017 · 15 comments
Closed

Auto-Update quitAndInstall Not Working On Mac #1604

daveywc opened this issue May 31, 2017 · 15 comments

Comments

@daveywc
Copy link

daveywc commented May 31, 2017

"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();
        }
    });
});`
@daveywc
Copy link
Author

daveywc commented Jun 7, 2017

I've made another donation. Any chance of getting some help with this issue?

@develar
Copy link
Member

develar commented Jun 7, 2017

Also on Mac my progress is not logged to my log file

Fixed in the electron-updater 2.0.0

@develar
Copy link
Member

develar commented Jun 7, 2017

It is not electron-updater issue. Please see electron/electron#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

@daveywc
Copy link
Author

daveywc commented Jun 7, 2017

Thanks @develar. Both issues are now resolved. Mac auto-updates are working nicely. Appreciate your help.

@Kunze
Copy link

Kunze commented Aug 2, 2017

Did not work for windows.
The app does not start after closing.

@yawar-ali
Copy link

yawar-ali commented Oct 24, 2017

@develar I am having same issue autoUpdater is working fine on windows but having issues on mac.
Electron Version: 1.7.5

app.on('ready', () => {
    // handle app updates
    if (process.env.NODE_ENV !== 'development') {
      autoUpdater.setFeedURL(updateFeedUrl);
      autoUpdater.on('error', (err) => {
        console.log(err);
      });
      // wait for things to settle in
      setTimeout(() => {
        checkForUpdates();
      }, 30000);
    }
    ipcMain.on('application:quit-install', () => autoUpdater.quitAndInstall());
    autoUpdater.on('update-downloaded', () => {
      updateDownloaded = true;
      dialog.showMessageBox({
        title: 'New Version Downloaded',
        message: 'The update will be applied the next time you start the app. Close and restart now to run the latest version.',
        buttons: ['Restart', 'Later'],
        icon: dialogIcon
      }, (response) => {
        if (response === 0) {
          autoUpdater.quitAndInstall();
        }
      });
    });
    autoUpdater.on('update-available', () => { updateAvailable = true;
      console.log('update-av', updateAvailable);
    });

    let opts = {
      show: false,
      width: 1200,
      height: 720,
      minWidth: 1200,
      minHeight: 720,
      titleBarStyle: 'hiddenInset'
    };
    Object.assign(opts, config.getData().winBounds);
    delete opts.fullscreen; // prevent app from launching fullscreen
    mainWindow = new BrowserWindow(opts);

    mainWindow.loadURL(`file://${__dirname}/app/app.html`);

    template = getTemplate();
    menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);
  });

@phuze
Copy link

phuze commented Nov 22, 2017

@SweetEvil unfortunately, the author left out a critical piece of information from the documentation -- auto updating will not work unless your Mac application is signed.

I found this out by reading through the electron docs for auto updating.

Your application must be signed for automatic updates on macOS. This is a requirement of Squirrel.Mac

As electron-builder makes use of Squirrel.Mac, this may be the cause of your issue.

@yawar-ali
Copy link

@purplekrayons My issue was with me using dmg format but zip format was needed to make it work. I just changed the format and it worked for our customers fine 👍

@phuze
Copy link

phuze commented Nov 24, 2017

@SweetEvil Most interesting. Are you signing your Mac app? I wasn't able to get mine working -- to note I am using .zip -- this makes me think perhaps I have another thats causing my mac clients not to auto-update.

@onassar
Copy link

onassar commented 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 :)

@garshythoel
Copy link

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 :)

This (we think) just solved a massive issue with our app's upgrade flow. Thanks!

@onassar
Copy link

onassar commented Feb 14, 2019

ps. my loom hasn't worked for ages ;)

olizilla added a commit to ipfs/ipfs-desktop that referenced this issue Mar 15, 2019
gotta clear all listeners on all the windows for quitAndInstall
to work. Now auto-update works as expected on mac.

thanks to the proposed fix on this issue:
electron-userland/electron-builder#1604 (comment)

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@Kirezi
Copy link

Kirezi commented Jun 1, 2021

@onassar where did you use that helper function, I run into similar issue but I can't fix the issue

@onassar
Copy link

onassar commented Jun 1, 2021

@Kirezi

Sadly, it's been years, and I ended up abandoning our attempt at a native (Electron wrapped) app. At the time, Electron required way (way way) too much low-level logic to work reliably. It's been years, so my guess is it's not as bad anymore. But I'm not sure where exactly I put that. Likely in the boot script (or whatever the language equivalent of that is these days).

@effectivecui
Copy link

It is not electron-updater issue. Please see electron/electron#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

thanks. @develar

avivm added a commit to krud-dev/ostara that referenced this issue Jul 4, 2023
* fix: app updater quit and install not working

electron-userland/electron-builder#1604

* docs(changeset): Fixed app updater quit and install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants