Open the error report in detached process

This commit is contained in:
Yuya Ochiai 2017-10-24 22:21:53 +09:00
parent 02c63395b5
commit 00b7a806ad

View file

@ -1,4 +1,5 @@
const {app, dialog, shell} = require('electron'); const {app, dialog} = require('electron');
const {spawn} = require('child_process');
const fs = require('fs'); const fs = require('fs');
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
@ -9,6 +10,20 @@ function createErrorReport(err) {
`${err.stack}`; `${err.stack}`;
} }
function openDetachedExternal(url) {
const spawnOption = {detached: true, stdio: 'ignore'};
switch (process.platform) {
case 'win32':
return spawn('cmd', ['/C', 'start', url], spawnOption);
case 'darwin':
return spawn('open', [url], spawnOption);
case 'linux':
return spawn('xdg-open', [url], spawnOption);
default:
return null;
}
}
function bindWindowToShowMessageBox(win) { function bindWindowToShowMessageBox(win) {
if (win && win.isVisible()) { if (win && win.isVisible()) {
return dialog.showMessageBox.bind(null, win); return dialog.showMessageBox.bind(null, win);
@ -54,7 +69,13 @@ class CriticalErrorHandler {
defaultId: 0 defaultId: 0
}); });
if (result === 1) { if (result === 1) {
shell.openExternal(file); const child = openDetachedExternal(file);
if (child) {
child.on('error', (spawnError) => {
console.log(spawnError);
});
child.unref();
}
} }
} }
throw err; throw err;