electron/lib/common/crash-reporter.js

99 lines
2.4 KiB
JavaScript
Raw Normal View History

'use strict'
const binding = process.electronBinding('crash_reporter')
2016-01-12 02:40:23 +00:00
class CrashReporter {
constructor () {
this.productName = null
this.crashesDirectory = null
}
2019-02-05 20:56:44 +00:00
init (options) {
throw new Error('Not implemented')
}
start (options) {
2017-10-31 02:51:22 +00:00
if (options == null) options = {}
2016-01-12 02:40:23 +00:00
const {
productName,
2017-10-31 02:51:22 +00:00
companyName,
extra = {},
ignoreSystemCrashHandler = false,
2017-10-31 02:51:22 +00:00
submitURL,
2018-05-23 16:07:14 +00:00
uploadToServer = true
} = options
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start')
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start')
2019-02-05 20:56:44 +00:00
const ret = this.init({
submitURL,
productName
})
this.productName = ret.productName
this.crashesDirectory = ret.crashesDirectory
if (extra._productName == null) extra._productName = ret.productName
if (extra._companyName == null) extra._companyName = companyName
if (extra._version == null) extra._version = ret.appVersion
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra)
}
2016-01-12 02:40:23 +00:00
getLastCrashReport () {
const reports = this.getUploadedReports()
2018-03-13 20:57:12 +00:00
.sort((a, b) => {
const ats = (a && a.date) ? new Date(a.date).getTime() : 0
const bts = (b && b.date) ? new Date(b.date).getTime() : 0
2018-03-13 20:57:12 +00:00
return bts - ats
})
2017-10-31 02:51:22 +00:00
return (reports.length > 0) ? reports[0] : null
}
2016-01-12 02:40:23 +00:00
getUploadedReports () {
const crashDir = this.getCrashesDirectory()
if (!crashDir) {
throw new Error('crashReporter has not been started')
}
return binding.getUploadedReports(crashDir)
}
2016-01-12 02:40:23 +00:00
getCrashesDirectory () {
return this.crashesDirectory
}
2016-11-22 08:30:20 +00:00
getUploadToServer () {
if (process.type === 'browser') {
2017-02-02 21:00:00 +00:00
return binding.getUploadToServer()
} else {
2016-11-22 08:30:20 +00:00
throw new Error('getUploadToServer can only be called from the main process')
}
2016-11-08 00:03:57 +00:00
}
2016-11-22 08:30:20 +00:00
setUploadToServer (uploadToServer) {
if (process.type === 'browser') {
2017-02-02 21:00:00 +00:00
return binding.setUploadToServer(uploadToServer)
} else {
2016-11-22 08:30:20 +00:00
throw new Error('setUploadToServer can only be called from the main process')
}
2016-11-08 00:03:57 +00:00
}
2017-02-02 22:23:21 +00:00
addExtraParameter (key, value) {
binding.addExtraParameter(key, value)
}
removeExtraParameter (key) {
binding.removeExtraParameter(key)
}
getParameters () {
2017-10-31 17:51:44 +00:00
return binding.getParameters()
}
}
module.exports = CrashReporter