2016-03-25 19:41:24 +00:00
|
|
|
'use strict'
|
2016-03-10 19:54:17 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
const os = require('os')
|
|
|
|
const path = require('path')
|
|
|
|
const spawn = require('child_process').spawn
|
|
|
|
const electron = require('electron')
|
|
|
|
const binding = process.atomBinding('crash_reporter')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
var CrashReporter = (function () {
|
|
|
|
function CrashReporter () {}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
CrashReporter.prototype.start = function (options) {
|
2016-04-28 16:48:13 +00:00
|
|
|
var app, args, autoSubmit, companyName, env, extra, ignoreSystemCrashHandler, start, submitURL
|
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
|
|
|
|
companyName = options.companyName
|
|
|
|
submitURL = options.submitURL
|
|
|
|
autoSubmit = options.autoSubmit
|
|
|
|
ignoreSystemCrashHandler = options.ignoreSystemCrashHandler
|
|
|
|
extra = options.extra
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
app = (process.type === 'browser' ? electron : electron.remote).app
|
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-03-10 19:54:17 +00:00
|
|
|
start = () => {
|
2016-03-25 19:41:24 +00:00
|
|
|
binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
if (process.platform === 'win32') {
|
2016-03-25 19:45:13 +00:00
|
|
|
args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1']
|
2016-01-12 02:40:23 +00:00
|
|
|
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-03-25 19:41:24 +00:00
|
|
|
return start()
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
CrashReporter.prototype.getLastCrashReport = function () {
|
|
|
|
var reports
|
|
|
|
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-03-25 19:41:24 +00:00
|
|
|
CrashReporter.prototype.getUploadedReports = function () {
|
|
|
|
var log, tmpdir
|
|
|
|
tmpdir = process.platform === 'win32' ? os.tmpdir() : '/tmp'
|
2016-03-25 19:45:13 +00:00
|
|
|
log = process.platform === 'darwin' ? path.join(tmpdir, this.productName + ' Crashes') : path.join(tmpdir, this.productName + ' Crashes', 'uploads.log')
|
2016-03-25 19:41:24 +00:00
|
|
|
return binding._getUploadedReports(log)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:41:24 +00:00
|
|
|
return CrashReporter
|
|
|
|
})()
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:45:13 +00:00
|
|
|
module.exports = new CrashReporter()
|