diff --git a/src/main/CriticalErrorHandler.js b/src/main/CriticalErrorHandler.js index 4fb3e03c..a4f13800 100644 --- a/src/main/CriticalErrorHandler.js +++ b/src/main/CriticalErrorHandler.js @@ -8,6 +8,8 @@ import path from 'path'; import {app, dialog} from 'electron'; +import log from 'electron-log'; + const BUTTON_OK = 'OK'; const BUTTON_SHOW_DETAILS = 'Show Details'; const BUTTON_REOPEN = 'Reopen'; @@ -32,13 +34,6 @@ function openDetachedExternal(url) { } } -function bindWindowToShowMessageBox(win) { - if (win && win.isVisible()) { - return dialog.showMessageBox.bind(null, win); - } - return dialog.showMessageBox; -} - export default class CriticalErrorHandler { constructor() { this.mainWindow = null; @@ -49,16 +44,17 @@ export default class CriticalErrorHandler { } windowUnresponsiveHandler() { - const result = dialog.showMessageBox(this.mainWindow, { + dialog.showMessageBox(this.mainWindow, { type: 'warning', title: app.name, message: 'The window is no longer responsive.\nDo you wait until the window becomes responsive again?', buttons: ['No', 'Yes'], defaultId: 0, + }).then(({response}) => { + if (response === 0) { + throw new Error('BrowserWindow \'unresponsive\' event has been emitted'); + } }); - if (result === 0) { - throw new Error('BrowserWindow \'unresponsive\' event has been emitted'); - } } processUncaughtExceptionHandler(err) { @@ -71,32 +67,42 @@ export default class CriticalErrorHandler { if (process.platform === 'darwin') { buttons.reverse(); } - const showMessageBox = bindWindowToShowMessageBox(this.mainWindow); - const result = showMessageBox({ - type: 'error', - title: app.name, - message: `The ${app.name} app quit unexpectedly. Click "Show Details" to learn more or "Reopen" to open the application again.\n\nInternal error: ${err.message}`, - buttons, - defaultId: buttons.indexOf(BUTTON_REOPEN), - noLink: true, - }); - switch (result) { - case buttons.indexOf(BUTTON_SHOW_DETAILS): + const bindWindow = this.mainWindow && this.mainWindow.isVisible() ? this.mainWindow : null; + dialog.showMessageBox( + bindWindow, { - const child = openDetachedExternal(file); + type: 'error', + title: app.name, + message: `The ${app.name} app quit unexpectedly. Click "Show Details" to learn more or "Reopen" to open the application again.\n\nInternal error: ${err.message}`, + buttons, + defaultId: buttons.indexOf(BUTTON_REOPEN), + noLink: true, + } + ).then(({response}) => { + let child; + switch (response) { + case buttons.indexOf(BUTTON_SHOW_DETAILS): + child = openDetachedExternal(file); if (child) { - child.on('error', (spawnError) => { - console.log(spawnError); - }); + child.on( + 'error', + (spawnError) => { + console.log(spawnError); + } + ); child.unref(); } + break; + case buttons.indexOf(BUTTON_REOPEN): + app.relaunch(); + break; } - break; - case buttons.indexOf(BUTTON_REOPEN): - app.relaunch(); - break; - } + app.exit(-1); + }); + } else { + log.err(`Window wasn't ready to handle the error: ${err}\ntrace: ${err.stack}`); + throw err; } - throw err; } } + diff --git a/src/main/allowProtocolDialog.js b/src/main/allowProtocolDialog.js index 807cf492..cb8769d8 100644 --- a/src/main/allowProtocolDialog.js +++ b/src/main/allowProtocolDialog.js @@ -57,7 +57,7 @@ function initDialogEvent(mainWindow) { ], cancelId: 2, noLink: true, - }, (response) => { + }).then(({response}) => { switch (response) { case 1: { allowedProtocols.push(protocol); diff --git a/src/main/autoUpdater.js b/src/main/autoUpdater.js index 873fcef1..10ea8d39 100644 --- a/src/main/autoUpdater.js +++ b/src/main/autoUpdater.js @@ -142,7 +142,7 @@ function initialize(appState, mainWindow, notifyOnly = false) { buttons: ['Close'], title: 'Your Desktop App is up to date', message: 'You have the latest version of the Mattermost Desktop App.', - }, () => {}); // eslint-disable-line no-empty-function + }); } setTimeout(() => { autoUpdater.checkForUpdates();