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

Notification unresponsive after ~40s of inactivity #20323

Closed
3 tasks done
alexanderturinske opened this issue Sep 23, 2019 · 4 comments
Closed
3 tasks done

Notification unresponsive after ~40s of inactivity #20323

alexanderturinske opened this issue Sep 23, 2019 · 4 comments

Comments

@alexanderturinske
Copy link
Contributor

alexanderturinske commented Sep 23, 2019

Preflight Checklist

Issue Details

  • Electron Version:
    • v6.0.8
  • Operating System:
    • macOS 10.14.6
  • Last Known Working Electron version:
    • N/A

Expected Behavior

  1. Open app
  2. Click Check for update menu item
  3. Update is found and starts downloading
  4. On download Notification pops up giving option to restart and install new version
  5. User waits ~40s because they were in the middle of something or whatever. Notification continues to show
  6. User clicks on notification to restart app
    • EXPECTED: App restarts and installs the new version OR the notification disappears when it no longer will register actions
    • ACTUAL: Notification disappears and the app remains

To Reproduce

// Pulled from Issue #1604
function ensureSafeQuitAndInstall() {
    app.removeAllListeners('window-all-closed');
    const browserWindows = BrowserWindow.getAllWindows();
    browserWindows.forEach(browserWindow => {
        browserWindow.removeAllListeners('close');
    });
    dialog.showErrorBox('Error', `no error, just closing`);
    autoUpdater.quitAndInstall();
}

/**
 * Shows the update available notification and restarts the app on acceptance
 * @returns {void} void
 */
autoUpdater.on('update-downloaded', () => {
    const notif = new Notification({
        title: 'Update Downloaded',
        body: 'Click to reload the application',
    });

    // Reload the app if clicked on
    notif.on('click', ev => {
        dialog.showErrorBox('Error', `no error, just clicked ${ev}`);
        try {
            ensureSafeQuitAndInstall();
        } catch (e) {
            dialog.showErrorBox('Error', `error: ${e}`);
        }
    });

    // Never called
    notif.on('close', ev => {
        dialog.showErrorBox('Error', `no error, closing action ${ev}`);
    });

    // Never called
    notif.on('error', err => {
        dialog.showErrorBox('Error', `error ${err}`);
    });

    notif.show();
});

Workaround

Create a setTimeout that automatically closes the Notification after ~30s

@alexanderturinske alexanderturinske changed the title Notification unresponsive after ~40s of inactivity, but does not close Notification unresponsive after ~40s of inactivity Sep 23, 2019
@MarshallOfSound
Copy link
Member

@alexanderturinske This is expected behavior, your notif object has been garbage collected (there is nothing retaining it?). You can easily work around this by doing global.notif = or otherwise holding a reference to the notification object till you are done with it

@alexanderturinske
Copy link
Contributor Author

🤦‍♂ Ah, thank you. That is not a problem I encounter very often.

@Crazie-ash
Copy link

Crazie-ash commented Oct 25, 2019

@alexanderturinske Have u found a way to set timeout for notifications which last more than 5secs? Guide me if u found one pls!

@alexanderturinske
Copy link
Contributor Author

alexanderturinske commented Oct 25, 2019

As discussed above, my issue was that my variable was being garbage collected, so I created a top-level variable to retain it as suggested.

// THIS IS THE CHANGE
// MAKE notif A TOP-LEVEL VARIABLE
let notif; 

// Pulled from Issue #1604
function ensureSafeQuitAndInstall() {
    app.removeAllListeners('window-all-closed');
    const browserWindows = BrowserWindow.getAllWindows();
    browserWindows.forEach(browserWindow => {
        browserWindow.removeAllListeners('close');
    });
    dialog.showErrorBox('Error', `no error, just closing`);
    autoUpdater.quitAndInstall();
}

/**
 * Shows the update available notification and restarts the app on acceptance
 * @returns {void} void
 */
autoUpdater.on('update-downloaded', () => {
    notif = new Notification({
        title: 'Update Downloaded',
        body: 'Click to reload the application',
    });

    // Reload the app if clicked on
    notif.on('click', ev => {
        dialog.showErrorBox('Error', `no error, just clicked ${ev}`);
        try {
            ensureSafeQuitAndInstall();
        } catch (e) {
            dialog.showErrorBox('Error', `error: ${e}`);
        }
    });

    // Is now called
    notif.on('close', ev => {
        dialog.showErrorBox('Error', `no error, closing action ${ev}`);
    });

    // Is now called
    notif.on('error', err => {
        dialog.showErrorBox('Error', `error ${err}`);
    });

    notif.show();
});

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

3 participants