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

Any hooks to subscribe to when autoupdate is about to update? #140

Open
yuvalkarmi opened this issue Feb 16, 2024 · 2 comments
Open

Any hooks to subscribe to when autoupdate is about to update? #140

yuvalkarmi opened this issue Feb 16, 2024 · 2 comments

Comments

@yuvalkarmi
Copy link

yuvalkarmi commented Feb 16, 2024

Are there any events that auto updater sends that I can hook into? Something like autoupdate.on('about-to-update', function(){ ... }).

I'll explain the use case:
My electron app prevent the app from quitting when a window closes on Mac (which is in line with how apps work on Mac).
Instead, I have a flag called shouldQuit and only if it's true I call app.quit().

However, this prevent the auto updater from working. When a user clicks on "Update now" when prompted, I need to be able to set the flag shouldQuit to true to allow the app to actually quit.

Couldn't find anything about it in the documentation.

Thanks!

@hackal
Copy link

hackal commented Mar 18, 2024

We had the same problem and solved it like this.

export function ensureSafeQuitAndInstall() {
    const electron = require('electron');
    const app = electron.app;
    const BrowserWindow = electron.BrowserWindow;
    app.removeAllListeners('window-all-closed');
    const browserWindows = BrowserWindow.getAllWindows();
    for (const browserWindow of browserWindows) {
        browserWindow.removeAllListeners('close');
    }
}

When user clicks Update now an event is send to the main process.

import { IpcMain, IpcMainEvent } from 'electron';
import { autoUpdater } from 'electron-updater';
import { ensureSafeQuitAndInstall } from '../utils';

ipcMain?.handle('update-and-restart', (_event: IpcMainEvent) => {
    ensureSafeQuitAndInstall();
    autoUpdater.quitAndInstall(true, true);
});

@yuvalkarmi
Copy link
Author

yuvalkarmi commented Mar 18, 2024

Dude, you're on fire today! I ended up moving to electron-builder and the electron-updater instead of the update-electron-app module, as the latter supports these events. Thanks!

By the way, why are you removing the listeners?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants