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 binding = process.atomBinding('crash_reporter')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-10-06 11:48:00 +00:00
|
|
|
const errorUtils = require('@electron/internal/common/error-utils')
|
2018-09-26 05:43:34 +00:00
|
|
|
|
2016-10-05 20:40:39 +00:00
|
|
|
class CrashReporter {
|
2018-09-26 05:43:34 +00:00
|
|
|
contructor () {
|
|
|
|
this.productName = null
|
|
|
|
this.crashesDirectory = null
|
|
|
|
}
|
|
|
|
|
2018-10-06 11:48:00 +00:00
|
|
|
sendSync (channel, ...args) {
|
|
|
|
throw new Error('Not implemented')
|
|
|
|
}
|
|
|
|
|
|
|
|
invoke (command, ...args) {
|
|
|
|
const [ error, result ] = this.sendSync(command, ...args)
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw errorUtils.deserialize(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2016-10-05 20:40:39 +00:00
|
|
|
start (options) {
|
2017-10-31 02:51:22 +00:00
|
|
|
if (options == null) options = {}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2017-10-31 02:51:22 +00:00
|
|
|
let {
|
2018-09-26 05:43:34 +00:00
|
|
|
productName,
|
2017-10-31 02:51:22 +00:00
|
|
|
companyName,
|
|
|
|
extra,
|
|
|
|
ignoreSystemCrashHandler,
|
|
|
|
submitURL,
|
|
|
|
uploadToServer
|
|
|
|
} = options
|
2016-11-28 22:51:24 +00:00
|
|
|
|
2018-02-21 04:31:48 +00:00
|
|
|
if (uploadToServer == null) {
|
2018-05-23 16:07:14 +00:00
|
|
|
uploadToServer = true
|
2018-02-21 04:31:48 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 05:43:34 +00:00
|
|
|
if (ignoreSystemCrashHandler == null) {
|
|
|
|
ignoreSystemCrashHandler = false
|
|
|
|
}
|
2016-11-28 22:51:24 +00:00
|
|
|
|
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
|
|
|
|
2018-10-06 11:48:00 +00:00
|
|
|
const ret = this.invoke('ELECTRON_CRASH_REPORTER_INIT', {
|
2018-09-26 05:43:34 +00:00
|
|
|
submitURL,
|
|
|
|
productName
|
|
|
|
})
|
|
|
|
|
|
|
|
this.productName = ret.productName
|
|
|
|
this.crashesDirectory = ret.crashesDirectory
|
|
|
|
|
|
|
|
if (extra == null) extra = {}
|
|
|
|
if (extra._productName == null) extra._productName = ret.productName
|
|
|
|
if (extra._companyName == null) extra._companyName = companyName
|
|
|
|
if (extra._version == null) extra._version = ret.appVersion
|
2016-10-05 20:40:39 +00:00
|
|
|
|
2018-09-26 05:43:34 +00:00
|
|
|
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, 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()
|
2018-03-13 20:57:12 +00:00
|
|
|
.sort((a, b) => {
|
2018-03-14 00:35:55 +00:00
|
|
|
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-03-25 19:41:24 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-10-05 20:40:39 +00:00
|
|
|
getUploadedReports () {
|
2017-02-13 18:46:19 +00:00
|
|
|
return binding.getUploadedReports(this.getCrashesDirectory())
|
2016-03-25 19:41:24 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-10-06 17:39:57 +00:00
|
|
|
getCrashesDirectory () {
|
2018-09-26 05:43:34 +00:00
|
|
|
return this.crashesDirectory
|
2016-10-06 17:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getProductName () {
|
|
|
|
return this.productName
|
|
|
|
}
|
|
|
|
|
2016-11-22 08:30:20 +00:00
|
|
|
getUploadToServer () {
|
2016-11-08 00:39:11 +00:00
|
|
|
if (process.type === 'browser') {
|
2017-02-02 21:00:00 +00:00
|
|
|
return binding.getUploadToServer()
|
2016-11-08 00:39:11 +00:00
|
|
|
} 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:39:11 +00:00
|
|
|
}
|
2016-11-08 00:03:57 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 08:30:20 +00:00
|
|
|
setUploadToServer (uploadToServer) {
|
2016-11-08 00:39:11 +00:00
|
|
|
if (process.type === 'browser') {
|
2017-02-02 21:00:00 +00:00
|
|
|
return binding.setUploadToServer(uploadToServer)
|
2016-11-08 00:39:11 +00:00
|
|
|
} 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:39:11 +00:00
|
|
|
}
|
2016-11-08 00:03:57 +00:00
|
|
|
}
|
2017-02-02 22:23:21 +00:00
|
|
|
|
2017-11-02 01:57:43 +00:00
|
|
|
addExtraParameter (key, value) {
|
|
|
|
binding.addExtraParameter(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
removeExtraParameter (key) {
|
|
|
|
binding.removeExtraParameter(key)
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:06:54 +00:00
|
|
|
getParameters (key, value) {
|
2017-10-31 17:51:44 +00:00
|
|
|
return binding.getParameters()
|
2017-10-31 17:06:54 +00:00
|
|
|
}
|
2016-10-06 17:02:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 11:48:00 +00:00
|
|
|
module.exports = CrashReporter
|