diff --git a/app/browser/error.ts b/app/browser/error.ts new file mode 100644 index 00000000..d3b98e80 --- /dev/null +++ b/app/browser/error.ts @@ -0,0 +1,38 @@ +import process from 'process' +import os from 'os' +import { dialog, clipboard } from 'electron' +import { PRODUCT_NAME } from 'constants/app' + +const isNativeDllError = (err: Error) => + os.platform() === 'win32' && + err.message.indexOf('The specified module could not be found') > -1 && + err.message.indexOf('dlopen') > -1 + +process.on('uncaughtException', err => { + const message = err.stack || err.message || 'Unknown error' + if (isNativeDllError(err)) { + dialog.showErrorBox( + 'Error: Missing native dependency', + `Please install 'Visual C++ Redistributable for Visual Studio 2015' to continue. + +${message}` + ) + } else { + const reportUrl = 'https://github.com/samuelmaddock/metastream/issues' + + console.error(message) + clipboard.writeText(`${reportUrl}\n${message}`) + + dialog.showErrorBox( + `${PRODUCT_NAME} Error`, + `An error occurred while running ${PRODUCT_NAME}. The program will terminate after closing this message. + +Please report this issue to the developer by creating an issue on GitHub. The full error message has been copied to your clipboard. +${reportUrl} + +${message}` + ) + } + + process.exit(1) +}) diff --git a/app/main.dev.ts b/app/main.dev.ts index ae82819e..bd7b7db9 100644 --- a/app/main.dev.ts +++ b/app/main.dev.ts @@ -1,12 +1,7 @@ -/** - * This module executes inside of electron's main process. You can start - * electron renderer process from here and communicate with the other processes - * through IPC. - * - * When running `npm run build` or `npm run build-main`, this file is compiled to - * `./app/main.prod.js` using webpack. This gives us some performance wins. - */ -import { app, BrowserWindow, globalShortcut, protocol } from 'electron' +// Error handling +import 'browser/error' + +import { app, BrowserWindow, globalShortcut } from 'electron' import { PRODUCT_NAME, VERSION } from 'constants/app' if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true') {