electron/lib/common/api/crash-reporter.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

'use strict'
const {spawn} = require('child_process')
const electron = require('electron')
const {app} = process.type === 'browser' ? electron : electron.remote
const binding = process.atomBinding('crash_reporter')
2016-01-12 02:40:23 +00:00
class CrashReporter {
start (options) {
2016-01-12 02:40:23 +00:00
if (options == null) {
options = {}
2016-01-12 02:40:23 +00:00
}
this.productName = options.productName
let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options
2016-01-12 02:40:23 +00:00
2016-10-05 22:23:51 +00:00
this.tempDirectory = app.getPath('temp')
2016-01-12 02:40:23 +00:00
if (this.productName == null) {
this.productName = app.getName()
2016-01-12 02:40:23 +00:00
}
if (autoSubmit == null) {
autoSubmit = true
2016-01-12 02:40:23 +00:00
}
if (ignoreSystemCrashHandler == null) {
ignoreSystemCrashHandler = false
2016-01-12 02:40:23 +00:00
}
if (extra == null) {
extra = {}
2016-01-12 02:40:23 +00:00
}
if (extra._productName == null) {
extra._productName = this.productName
2016-01-12 02:40:23 +00:00
}
if (extra._companyName == null) {
extra._companyName = companyName
2016-01-12 02:40:23 +00:00
}
if (extra._version == null) {
extra._version = app.getVersion()
2016-01-12 02:40:23 +00:00
}
if (companyName == null) {
throw new Error('companyName is a required option to crashReporter.start')
2016-01-12 02:40:23 +00:00
}
if (submitURL == null) {
throw new Error('submitURL is a required option to crashReporter.start')
2016-01-12 02:40:23 +00:00
}
2016-01-12 02:40:23 +00:00
if (process.platform === 'win32') {
const args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1']
const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
}
2016-01-12 02:40:23 +00:00
spawn(process.execPath, args, {
env: env,
detached: true
})
2016-01-12 02:40:23 +00:00
}
2016-10-05 22:23:51 +00:00
binding.start(this.productName, companyName, submitURL, this.tempDirectory, autoSubmit, ignoreSystemCrashHandler, extra)
}
2016-01-12 02:40:23 +00:00
getLastCrashReport () {
const reports = this.getUploadedReports()
2016-01-12 02:40:23 +00:00
if (reports.length > 0) {
return reports[0]
2016-01-12 02:40:23 +00:00
} else {
return null
2016-01-12 02:40:23 +00:00
}
}
2016-01-12 02:40:23 +00:00
getUploadedReports () {
const productName = this.productName != null ? this.productName : app.getName()
const tempDirectory = this.tempDirectory != null ? this.tempDirectory : app.getPath('temp')
return binding._getUploadedReports(productName, tempDirectory)
}
}
2016-01-12 02:40:23 +00:00
2016-03-25 19:45:13 +00:00
module.exports = new CrashReporter()