refactor: implement crashReporter.start() without the remote module (#14434)

This commit is contained in:
Milan Burda 2018-09-26 07:43:34 +02:00 committed by Samuel Attard
parent 560b1c17af
commit 3df739fa89
3 changed files with 71 additions and 50 deletions

View file

@ -1,8 +1,11 @@
'use strict'
const { spawn } = require('child_process')
const electron = require('electron')
const { EventEmitter } = require('events')
const fs = require('fs')
const os = require('os')
const path = require('path')
const v8Util = process.atomBinding('v8_util')
const { ipcMain, isPromise } = electron
@ -396,6 +399,42 @@ ipcMain.on('ELECTRON_BROWSER_WINDOW_CLOSE', function (event) {
event.returnValue = null
})
const getTempDirectory = function () {
try {
return electron.app.getPath('temp')
} catch (error) {
return os.tmpdir()
}
}
ipcMain.on('ELECTRON_CRASH_REPORTER_INIT', function (event, options) {
const productName = options.productName || electron.app.getName()
const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`)
if (process.platform === 'win32') {
const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
}
const args = [
'--reporter-url=' + options.submitURL,
'--application-name=' + productName,
'--crashes-directory=' + crashesDirectory,
'--v=1'
]
spawn(process.helperExecPath, args, {
env,
detached: true
})
}
event.returnValue = {
productName,
crashesDirectory,
appVersion: electron.app.getVersion()
}
})
ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {
const preloadPath = event.sender._getPreloadPath()
let preloadSrc = null