[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:
parent
1a217853d7
commit
877f81d430
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ function initDialogEvent(mainWindow) {
|
|||
],
|
||||
cancelId: 2,
|
||||
noLink: true,
|
||||
}, (response) => {
|
||||
}).then(({response}) => {
|
||||
switch (response) {
|
||||
case 1: {
|
||||
allowedProtocols.push(protocol);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue