[MM-22230] fix promises, reenable trust protocols, reenable capturing unhandled exceptions (#1315)

* [MM-22230] migrate dialogs to promises if needed

* object response, actually capture and show the screen

* make app close if user chooses ok
This commit is contained in:
Guillermo Vayá 2020-06-08 10:03:21 +02:00 committed by GitHub
parent 1a217853d7
commit 877f81d430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 34 deletions

View file

@ -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;
}
}

View file

@ -57,7 +57,7 @@ function initDialogEvent(mainWindow) {
],
cancelId: 2,
noLink: true,
}, (response) => {
}).then(({response}) => {
switch (response) {
case 1: {
allowedProtocols.push(protocol);

View file

@ -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();