7
7
import {
8
8
app ,
9
9
BrowserWindow ,
10
+ crashReporter ,
10
11
protocol as electronProtocol ,
11
12
ipcMain as ipc ,
12
13
ipcMain ,
@@ -20,7 +21,7 @@ import {
20
21
} from 'electron' ;
21
22
22
23
import crypto from 'crypto' ;
23
- import fs from 'fs' ;
24
+ import fs , { appendFileSync } from 'fs' ;
24
25
import os from 'os' ;
25
26
import path , { join } from 'path' ;
26
27
import { platform as osPlatform } from 'process' ;
@@ -152,6 +153,12 @@ if (!process.mas) {
152
153
}
153
154
}
154
155
156
+ crashReporter . start ( {
157
+ submitURL : '' , // leave empty if you don’t want to upload
158
+ uploadToServer : false ,
159
+ compress : true ,
160
+ } ) ;
161
+
155
162
const windowFromUserConfig = userConfig . get ( 'window' ) ;
156
163
const windowFromEphemeral = ephemeralConfig . get ( 'window' ) ;
157
164
let windowConfig = windowFromEphemeral || windowFromUserConfig ;
@@ -360,6 +367,17 @@ async function createWindow() {
360
367
mainWindow . on ( 'focus' , setWindowFocus ) ;
361
368
mainWindow . on ( 'blur' , setWindowFocus ) ;
362
369
mainWindow . once ( 'ready-to-show' , setWindowFocus ) ;
370
+ function logCrash ( type : string , details : any ) {
371
+ const crashLogPath = path . join ( app . getPath ( 'userData' ) , 'crash-log.txt' ) ;
372
+ const logLine = `[${ new Date ( ) . toISOString ( ) } ] ${ type } crash: ${ JSON . stringify ( details ) } \n` ;
373
+ appendFileSync ( crashLogPath , logLine , 'utf8' ) ;
374
+ }
375
+
376
+ mainWindow . webContents . on ( 'render-process-gone' , ( _event , details ) => {
377
+ // details.reason can be: 'crashed', 'killed', 'oom', etc.
378
+ logCrash ( 'renderer' , details ) ;
379
+ } ) ;
380
+
363
381
// This is a fallback in case we drop an event for some reason.
364
382
global . setInterval ( setWindowFocus , 5000 ) ;
365
383
0 commit comments