You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
| const electron = require('electron');
 | |
| 
 | |
| const Errors = require('../js/modules/types/errors');
 | |
| 
 | |
| const { app, dialog, clipboard } = electron;
 | |
| const { redactAll } = require('../js/modules/privacy');
 | |
| 
 | |
| // We use hard-coded strings until we're able to update these strings from the locale.
 | |
| let quitText = 'Quit';
 | |
| let copyErrorAndQuitText = 'Copy error and quit';
 | |
| 
 | |
| 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: [quitText, copyErrorAndQuitText],
 | |
|       defaultId: 0,
 | |
|       detail: redactAll(error.stack),
 | |
|       message: prefix,
 | |
|       noLink: true,
 | |
|       type: 'error',
 | |
|     });
 | |
| 
 | |
|     if (buttonIndex === 1) {
 | |
|       clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`);
 | |
|     }
 | |
|   } else {
 | |
|     dialog.showErrorBox(prefix, error.stack);
 | |
|   }
 | |
| 
 | |
|   app.exit(1);
 | |
| }
 | |
| 
 | |
| exports.updateLocale = messages => {
 | |
|   quitText = messages.quit.message;
 | |
|   copyErrorAndQuitText = messages.copyErrorAndQuit.message;
 | |
| };
 | |
| 
 | |
| exports.addHandler = () => {
 | |
|   process.on('uncaughtException', error => {
 | |
|     handleError('Unhandled Error', error);
 | |
|   });
 | |
| 
 | |
|   process.on('unhandledRejection', error => {
 | |
|     handleError('Unhandled Promise Rejection', error);
 | |
|   });
 | |
| };
 |