[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:
@@ -8,6 +8,8 @@ import path from 'path';
|
|||||||
|
|
||||||
import {app, dialog} from 'electron';
|
import {app, dialog} from 'electron';
|
||||||
|
|
||||||
|
import log from 'electron-log';
|
||||||
|
|
||||||
const BUTTON_OK = 'OK';
|
const BUTTON_OK = 'OK';
|
||||||
const BUTTON_SHOW_DETAILS = 'Show Details';
|
const BUTTON_SHOW_DETAILS = 'Show Details';
|
||||||
const BUTTON_REOPEN = 'Reopen';
|
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 {
|
export default class CriticalErrorHandler {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.mainWindow = null;
|
this.mainWindow = null;
|
||||||
@@ -49,16 +44,17 @@ export default class CriticalErrorHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
windowUnresponsiveHandler() {
|
windowUnresponsiveHandler() {
|
||||||
const result = dialog.showMessageBox(this.mainWindow, {
|
dialog.showMessageBox(this.mainWindow, {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
title: app.name,
|
title: app.name,
|
||||||
message: 'The window is no longer responsive.\nDo you wait until the window becomes responsive again?',
|
message: 'The window is no longer responsive.\nDo you wait until the window becomes responsive again?',
|
||||||
buttons: ['No', 'Yes'],
|
buttons: ['No', 'Yes'],
|
||||||
defaultId: 0,
|
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) {
|
processUncaughtExceptionHandler(err) {
|
||||||
@@ -71,32 +67,42 @@ export default class CriticalErrorHandler {
|
|||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
buttons.reverse();
|
buttons.reverse();
|
||||||
}
|
}
|
||||||
const showMessageBox = bindWindowToShowMessageBox(this.mainWindow);
|
const bindWindow = this.mainWindow && this.mainWindow.isVisible() ? this.mainWindow : null;
|
||||||
const result = showMessageBox({
|
dialog.showMessageBox(
|
||||||
type: 'error',
|
bindWindow,
|
||||||
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 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) {
|
if (child) {
|
||||||
child.on('error', (spawnError) => {
|
child.on(
|
||||||
console.log(spawnError);
|
'error',
|
||||||
});
|
(spawnError) => {
|
||||||
|
console.log(spawnError);
|
||||||
|
}
|
||||||
|
);
|
||||||
child.unref();
|
child.unref();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case buttons.indexOf(BUTTON_REOPEN):
|
||||||
|
app.relaunch();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
app.exit(-1);
|
||||||
case buttons.indexOf(BUTTON_REOPEN):
|
});
|
||||||
app.relaunch();
|
} else {
|
||||||
break;
|
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,
|
cancelId: 2,
|
||||||
noLink: true,
|
noLink: true,
|
||||||
}, (response) => {
|
}).then(({response}) => {
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 1: {
|
case 1: {
|
||||||
allowedProtocols.push(protocol);
|
allowedProtocols.push(protocol);
|
||||||
|
@@ -142,7 +142,7 @@ function initialize(appState, mainWindow, notifyOnly = false) {
|
|||||||
buttons: ['Close'],
|
buttons: ['Close'],
|
||||||
title: 'Your Desktop App is up to date',
|
title: 'Your Desktop App is up to date',
|
||||||
message: 'You have the latest version of the Mattermost Desktop App.',
|
message: 'You have the latest version of the Mattermost Desktop App.',
|
||||||
}, () => {}); // eslint-disable-line no-empty-function
|
});
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
|
Reference in New Issue
Block a user