1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00

Desktop: Resolves #9480: Cancel showing unresponsive dialog when receiving "responsive" event (#9487)

This commit is contained in:
Henry Heino 2023-12-13 11:45:29 -08:00 committed by GitHub
parent 19b68102b2
commit d17e36d038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ const fs = require('fs-extra');
import { dialog, ipcMain } from 'electron';
import { _ } from '@joplin/lib/locale';
import restartInSafeModeFromMain from './utils/restartInSafeModeFromMain';
import { clearTimeout, setTimeout } from 'timers';
interface RendererProcessQuitReply {
canClose: boolean;
@ -160,8 +161,28 @@ export default class ElectronAppWrapper {
this.win_.setPosition(primaryDisplayWidth / 2 - windowWidth, primaryDisplayHeight / 2 - windowHeight);
}
this.win_.webContents.on('unresponsive', async () => {
await this.handleAppFailure(_('Window unresponsive.'), true);
let unresponsiveTimeout: ReturnType<typeof setTimeout>|null = null;
this.win_.webContents.on('unresponsive', () => {
// Don't show the "unresponsive" dialog immediately -- the "unresponsive" event
// can be fired when showing a dialog or modal (e.g. the update dialog).
//
// This gives us an opportunity to cancel it.
if (unresponsiveTimeout === null) {
const delayMs = 1000;
unresponsiveTimeout = setTimeout(() => {
unresponsiveTimeout = null;
void this.handleAppFailure(_('Window unresponsive.'), true);
}, delayMs);
}
});
this.win_.webContents.on('responsive', () => {
if (unresponsiveTimeout !== null) {
clearTimeout(unresponsiveTimeout);
unresponsiveTimeout = null;
}
});
this.win_.webContents.on('render-process-gone', async _event => {