Show dialog if application fails to start up properly
This commit is contained in:
parent
ec12733dad
commit
68af1ae1ea
3 changed files with 37 additions and 15 deletions
|
@ -1,16 +1,43 @@
|
|||
const addUnhandledErrorHandler = require('electron-unhandled');
|
||||
const electron = require('electron');
|
||||
|
||||
const Errors = require('../js/modules/types/errors');
|
||||
|
||||
// addHandler :: Unit -> Unit
|
||||
const { app, dialog, clipboard } = electron;
|
||||
|
||||
// We're using hard-coded strings in this file because it needs to be ready
|
||||
// to report errors before we do anything in the app. Also, we expect users to directly
|
||||
// paste this text into search engines to find the bugs on GitHub.
|
||||
|
||||
function handleError(prefix, error) {
|
||||
console.error(`${prefix}:`, Errors.toLogFormat(error));
|
||||
|
||||
if (app.isReady()) {
|
||||
// title field is not shown on macOS, so we don't use it
|
||||
const buttonIndex = dialog.showMessageBox({
|
||||
buttons: ['OK', 'Copy error'],
|
||||
defaultId: 0,
|
||||
detail: error.stack,
|
||||
message: prefix,
|
||||
noLink: true,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
if (buttonIndex === 1) {
|
||||
clipboard.writeText(`${prefix}\n${error.stack}`);
|
||||
}
|
||||
} else {
|
||||
dialog.showErrorBox(prefix, error.stack);
|
||||
}
|
||||
|
||||
app.quit();
|
||||
}
|
||||
|
||||
exports.addHandler = () => {
|
||||
addUnhandledErrorHandler({
|
||||
logger: error => {
|
||||
console.error(
|
||||
'Uncaught error or unhandled promise rejection:',
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
},
|
||||
showDialog: false,
|
||||
process.on('uncaughtException', error => {
|
||||
handleError('Unhandled Error', error);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
handleError('Unhandled Promise Rejection', error);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
"config": "1.28.1",
|
||||
"electron-editor-context-menu": "1.1.1",
|
||||
"electron-is-dev": "0.3.0",
|
||||
"electron-unhandled": "https://github.com/scottnonnenberg-signal/electron-unhandled.git#7496187472aa561d39fcd4c843a54ffbef0a388c",
|
||||
"electron-updater": "2.21.10",
|
||||
"emoji-datasource": "4.0.0",
|
||||
"emoji-datasource-apple": "4.0.0",
|
||||
|
|
|
@ -2520,10 +2520,6 @@ electron-to-chromium@^1.2.7:
|
|||
version "1.3.41"
|
||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.41.tgz#7e33643e00cd85edfd17e04194f6d00e73737235"
|
||||
|
||||
"electron-unhandled@https://github.com/scottnonnenberg-signal/electron-unhandled.git#7496187472aa561d39fcd4c843a54ffbef0a388c":
|
||||
version "1.0.0"
|
||||
resolved "https://github.com/scottnonnenberg-signal/electron-unhandled.git#7496187472aa561d39fcd4c843a54ffbef0a388c"
|
||||
|
||||
electron-updater@2.21.10:
|
||||
version "2.21.10"
|
||||
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-2.21.10.tgz#aa66757ebf966f4247f247a8433af45cfe8e93b0"
|
||||
|
|
Loading…
Add table
Reference in a new issue