From 28d982623645f424f9d36462c9b2e8cffee2741e Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Fri, 11 Jan 2019 11:37:59 +0530 Subject: [PATCH] ELECTRON-816: add checks for crash events when it is killed (#544) Currently on Windows, when the app is killed, a crash event is emitted which sends the wrong signal to the user that the app actually crashed which isn't the case because the app was in fact killed. So, this PR adds an extra check to see if the app was killed and shows the crash dialog based on that. --- js/aboutApp/index.js | 11 +++++++++-- js/basicAuth/index.js | 11 +++++++++-- js/desktopCapturer/index.js | 11 +++++++++-- js/moreInfo/index.js | 11 +++++++++-- js/screenSharingIndicator/index.js | 13 ++++++++++--- js/windowMgr.js | 19 +++++++++++++++---- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/js/aboutApp/index.js b/js/aboutApp/index.js index afbe9ad8..e472bb20 100644 --- a/js/aboutApp/index.js +++ b/js/aboutApp/index.js @@ -95,7 +95,14 @@ function openAboutWindow(windowName) { } }); - aboutWindow.webContents.on('crashed', function () { + aboutWindow.webContents.on('crashed', function (event, killed) { + + log.send(logLevels.INFO, `About Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -129,4 +136,4 @@ function destroyWindow() { module.exports = { openAboutWindow: openAboutWindow -}; \ No newline at end of file +}; diff --git a/js/basicAuth/index.js b/js/basicAuth/index.js index 05afc89d..6c9a4168 100644 --- a/js/basicAuth/index.js +++ b/js/basicAuth/index.js @@ -111,7 +111,14 @@ function openBasicAuthWindow(windowName, hostname, isValidCredentials, clearSett } }); - basicAuthWindow.webContents.on('crashed', function () { + basicAuthWindow.webContents.on('crashed', function (event, killed) { + + log.send(logLevels.INFO, `Basic Auth Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -167,4 +174,4 @@ function closeAuthWindow(clearSettings) { module.exports = { openBasicAuthWindow: openBasicAuthWindow -}; \ No newline at end of file +}; diff --git a/js/desktopCapturer/index.js b/js/desktopCapturer/index.js index 087f6751..fa4fa516 100644 --- a/js/desktopCapturer/index.js +++ b/js/desktopCapturer/index.js @@ -106,7 +106,14 @@ function openScreenPickerWindow(eventSender, sources, id) { screenPickerWindow.webContents.send('desktop-capturer-sources', sources, isWindowsOS); }); - screenPickerWindow.webContents.on('crashed', function () { + screenPickerWindow.webContents.on('crashed', function (event, killed) { + + log.send(logLevels.INFO, `Screen Picker Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -164,4 +171,4 @@ ipc.on('close-screen-picker', () => { module.exports = { openScreenPickerWindow -}; \ No newline at end of file +}; diff --git a/js/moreInfo/index.js b/js/moreInfo/index.js index e249bd68..f4a02858 100644 --- a/js/moreInfo/index.js +++ b/js/moreInfo/index.js @@ -95,7 +95,14 @@ function openMoreInfoWindow(windowName) { } }); - moreInfoWindow.webContents.on('crashed', function () { + moreInfoWindow.webContents.on('crashed', function (event, killed) { + + log.send(logLevels.INFO, `More Info Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -129,4 +136,4 @@ function destroyWindow() { module.exports = { openMoreInfoWindow: openMoreInfoWindow -}; \ No newline at end of file +}; diff --git a/js/screenSharingIndicator/index.js b/js/screenSharingIndicator/index.js index 9045fd6a..e1919237 100755 --- a/js/screenSharingIndicator/index.js +++ b/js/screenSharingIndicator/index.js @@ -69,7 +69,14 @@ function openScreenSharingIndicator(eventSender, displayId, id) { }); }); - indicatorWindow.webContents.on('crashed', () => { + indicatorWindow.webContents.on('crashed', (event, killed) => { + + log.send(logLevels.INFO, `Screen Sharing Indicator Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const errorDialogOptions = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -83,7 +90,7 @@ function openScreenSharingIndicator(eventSender, displayId, id) { if (indicatorId === id) { eventSender.send('stop-sharing-requested', id); } - } + }; const handleDestroyScreensharingIndicator = (event, indicatorId) => { if (indicatorId === id) { @@ -101,4 +108,4 @@ function openScreenSharingIndicator(eventSender, displayId, id) { module.exports = { openScreenSharingIndicator -}; \ No newline at end of file +}; diff --git a/js/windowMgr.js b/js/windowMgr.js index e7f30e5e..83776148 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -327,7 +327,14 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) { // In case a renderer process crashes, provide an // option for the user to either reload or close the window - mainWindow.webContents.on('crashed', function () { + mainWindow.webContents.on('crashed', function (event, killed) { + + log.send(logLevels.INFO, `Main Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } + const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -506,8 +513,12 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) { browserWin.setAlwaysOnTop(alwaysOnTop); logBrowserWindowEvents(browserWin, browserWin.winName); - let handleChildWindowCrashEvent = (e) => { - log.send(logLevels.INFO, `Child Window crashed!`); + let handleChildWindowCrashEvent = (e, killed) => { + log.send(logLevels.INFO, `Child Window crashed! Killed? ${killed}`); + + if (killed) { + return; + } const options = { type: 'error', title: i18n.getMessageFor('Renderer Process Crashed'), @@ -996,7 +1007,7 @@ function isAlwaysOnTop(boolean, shouldActivateMainWindow = true) { } // node event emitter to update always on top -eventEmitter.on('isAlwaysOnTop', (params) => { +eventEmitter.on('isAlwaysOnTop', (params) => { isAlwaysOnTop(params.isAlwaysOnTop, params.shouldActivateMainWindow); log.send(logLevels.INFO, `Updating settings for always on top ${params}`); });