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

89 lines
2.6 KiB
JavaScript
Raw Normal View History

'use strict'
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
var CrashReporter = (function () {
function CrashReporter () {}
2016-01-12 02:40:23 +00:00
CrashReporter.prototype.start = function (options) {
var app, args, autoSubmit, companyName, env, extra, ignoreSystemCrashHandler, start, submitURL
2016-01-12 02:40:23 +00:00
if (options == null) {
options = {}
2016-01-12 02:40:23 +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
app = (process.type === 'browser' ? electron : electron.remote).app
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
}
start = () => {
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 = {
ATOM_SHELL_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
}
return start()
}
2016-01-12 02:40:23 +00:00
CrashReporter.prototype.getLastCrashReport = function () {
var reports
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
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')
return binding._getUploadedReports(log)
}
2016-01-12 02:40:23 +00:00
return CrashReporter
})()
2016-01-12 02:40:23 +00:00
2016-03-25 19:45:13 +00:00
module.exports = new CrashReporter()