electron/lib/common/crash-reporter.js

94 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict'
const binding = process.electronBinding('crash_reporter')
2016-01-11 18:40:23 -08:00
class CrashReporter {
contructor () {
this.productName = null
this.crashesDirectory = null
}
2019-02-05 21:56:44 +01:00
init (options) {
throw new Error('Not implemented')
}
start (options) {
2017-10-30 22:51:22 -04:00
if (options == null) options = {}
2016-01-11 18:40:23 -08:00
const {
productName,
2017-10-30 22:51:22 -04:00
companyName,
extra = {},
ignoreSystemCrashHandler = false,
2017-10-30 22:51:22 -04:00
submitURL,
2018-05-23 09:07:14 -07: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 21:56:44 +01: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-11 18:40:23 -08:00
getLastCrashReport () {
const reports = this.getUploadedReports()
2018-03-13 13:57:12 -07: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 13:57:12 -07:00
return bts - ats
})
2017-10-30 22:51:22 -04:00
return (reports.length > 0) ? reports[0] : null
}
2016-01-11 18:40:23 -08:00
getUploadedReports () {
2017-02-13 10:46:19 -08:00
return binding.getUploadedReports(this.getCrashesDirectory())
}
2016-01-11 18:40:23 -08:00
getCrashesDirectory () {
return this.crashesDirectory
}
2016-11-22 19:30:20 +11:00
getUploadToServer () {
if (process.type === 'browser') {
2017-02-02 13:00:00 -08:00
return binding.getUploadToServer()
} else {
2016-11-22 19:30:20 +11:00
throw new Error('getUploadToServer can only be called from the main process')
}
2016-11-08 11:03:57 +11:00
}
2016-11-22 19:30:20 +11:00
setUploadToServer (uploadToServer) {
if (process.type === 'browser') {
2017-02-02 13:00:00 -08:00
return binding.setUploadToServer(uploadToServer)
} else {
2016-11-22 19:30:20 +11:00
throw new Error('setUploadToServer can only be called from the main process')
}
2016-11-08 11:03:57 +11:00
}
2017-02-02 14:23:21 -08:00
addExtraParameter (key, value) {
binding.addExtraParameter(key, value)
}
removeExtraParameter (key) {
binding.removeExtraParameter(key)
}
getParameters () {
2017-10-31 13:51:44 -04:00
return binding.getParameters()
}
}
module.exports = CrashReporter