Relaunch the app by Reopen button and tweak for macOS
This commit is contained in:
@@ -4,6 +4,10 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const BUTTON_OK = 'OK';
|
||||||
|
const BUTTON_SHOW_DETAILS = 'Show Details';
|
||||||
|
const BUTTON_REOPEN = 'Reopen';
|
||||||
|
|
||||||
function createErrorReport(err) {
|
function createErrorReport(err) {
|
||||||
return `Application: ${app.getName()} ${app.getVersion()}\n` +
|
return `Application: ${app.getName()} ${app.getVersion()}\n` +
|
||||||
`Platform: ${os.type()} ${os.release()} ${os.arch()}\n` +
|
`Platform: ${os.type()} ${os.release()} ${os.arch()}\n` +
|
||||||
@@ -59,23 +63,34 @@ class CriticalErrorHandler {
|
|||||||
fs.writeFileSync(file, report.replace(new RegExp('\\n', 'g'), os.EOL));
|
fs.writeFileSync(file, report.replace(new RegExp('\\n', 'g'), os.EOL));
|
||||||
|
|
||||||
if (app.isReady()) {
|
if (app.isReady()) {
|
||||||
|
const buttons = [BUTTON_SHOW_DETAILS, BUTTON_OK, BUTTON_REOPEN];
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
buttons.reverse();
|
||||||
|
}
|
||||||
const showMessageBox = bindWindowToShowMessageBox(this.mainWindow);
|
const showMessageBox = bindWindowToShowMessageBox(this.mainWindow);
|
||||||
const result = showMessageBox({
|
const result = showMessageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
title: app.getName(),
|
title: app.getName(),
|
||||||
message: `The ${app.getName()} app quit unexpectedly. Click "Show Details" to learn more.\n\n Internal error: ${err.message}`,
|
message: `The ${app.getName()} app quit unexpectedly. Click "Show Details" to learn more or "Reopen" to open the application again.\n\n Internal error: ${err.message}`,
|
||||||
buttons: ['Show details', 'OK'],
|
buttons,
|
||||||
defaultId: 1,
|
defaultId: buttons.indexOf(BUTTON_REOPEN),
|
||||||
noLink: true
|
noLink: true
|
||||||
});
|
});
|
||||||
if (result === 0) {
|
switch (result) {
|
||||||
const child = openDetachedExternal(file);
|
case buttons.indexOf(BUTTON_SHOW_DETAILS):
|
||||||
if (child) {
|
{
|
||||||
child.on('error', (spawnError) => {
|
const child = openDetachedExternal(file);
|
||||||
console.log(spawnError);
|
if (child) {
|
||||||
});
|
child.on('error', (spawnError) => {
|
||||||
child.unref();
|
console.log(spawnError);
|
||||||
|
});
|
||||||
|
child.unref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case buttons.indexOf(BUTTON_REOPEN):
|
||||||
|
app.relaunch();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
Reference in New Issue
Block a user