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