|
@@ -1,18 +1,29 @@
|
|
|
'use strict'
|
|
|
|
|
|
-const { spawn } = require('child_process')
|
|
|
-const os = require('os')
|
|
|
-const path = require('path')
|
|
|
const electron = require('electron')
|
|
|
-const { app } = process.type === 'browser' ? electron : electron.remote
|
|
|
const binding = process.atomBinding('crash_reporter')
|
|
|
|
|
|
+const sendSync = function (channel, ...args) {
|
|
|
+ if (process.type === 'browser') {
|
|
|
+ let event = {}
|
|
|
+ electron.ipcMain.emit(channel, event, ...args)
|
|
|
+ return event.returnValue
|
|
|
+ } else {
|
|
|
+ return electron.ipcRenderer.sendSync(channel, ...args)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class CrashReporter {
|
|
|
+ contructor () {
|
|
|
+ this.productName = null
|
|
|
+ this.crashesDirectory = null
|
|
|
+ }
|
|
|
+
|
|
|
start (options) {
|
|
|
if (options == null) options = {}
|
|
|
- this.productName = options.productName != null ? options.productName : app.getName()
|
|
|
|
|
|
let {
|
|
|
+ productName,
|
|
|
companyName,
|
|
|
extra,
|
|
|
ignoreSystemCrashHandler,
|
|
@@ -24,12 +35,9 @@ class CrashReporter {
|
|
|
uploadToServer = true
|
|
|
}
|
|
|
|
|
|
- if (ignoreSystemCrashHandler == null) ignoreSystemCrashHandler = false
|
|
|
- if (extra == null) extra = {}
|
|
|
-
|
|
|
- if (extra._productName == null) extra._productName = this.getProductName()
|
|
|
- if (extra._companyName == null) extra._companyName = companyName
|
|
|
- if (extra._version == null) extra._version = app.getVersion()
|
|
|
+ if (ignoreSystemCrashHandler == null) {
|
|
|
+ ignoreSystemCrashHandler = false
|
|
|
+ }
|
|
|
|
|
|
if (companyName == null) {
|
|
|
throw new Error('companyName is a required option to crashReporter.start')
|
|
@@ -38,24 +46,20 @@ class CrashReporter {
|
|
|
throw new Error('submitURL is a required option to crashReporter.start')
|
|
|
}
|
|
|
|
|
|
- if (process.platform === 'win32') {
|
|
|
- const env = {
|
|
|
- ELECTRON_INTERNAL_CRASH_SERVICE: 1
|
|
|
- }
|
|
|
- const args = [
|
|
|
- '--reporter-url=' + submitURL,
|
|
|
- '--application-name=' + this.getProductName(),
|
|
|
- '--crashes-directory=' + this.getCrashesDirectory(),
|
|
|
- '--v=1'
|
|
|
- ]
|
|
|
-
|
|
|
- this._crashServiceProcess = spawn(process.execPath, args, {
|
|
|
- env: env,
|
|
|
- detached: true
|
|
|
- })
|
|
|
- }
|
|
|
+ const ret = sendSync('ELECTRON_CRASH_REPORTER_INIT', {
|
|
|
+ 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
|
|
|
|
|
|
- binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), uploadToServer, ignoreSystemCrashHandler, extra)
|
|
|
+ binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra)
|
|
|
}
|
|
|
|
|
|
getLastCrashReport () {
|
|
@@ -74,28 +78,13 @@ class CrashReporter {
|
|
|
}
|
|
|
|
|
|
getCrashesDirectory () {
|
|
|
- const crashesDir = `${this.getProductName()} Crashes`
|
|
|
- return path.join(this.getTempDirectory(), crashesDir)
|
|
|
+ return this.crashesDirectory
|
|
|
}
|
|
|
|
|
|
getProductName () {
|
|
|
- if (this.productName == null) {
|
|
|
- this.productName = app.getName()
|
|
|
- }
|
|
|
return this.productName
|
|
|
}
|
|
|
|
|
|
- getTempDirectory () {
|
|
|
- if (this.tempDirectory == null) {
|
|
|
- try {
|
|
|
- this.tempDirectory = app.getPath('temp')
|
|
|
- } catch (error) {
|
|
|
- this.tempDirectory = os.tmpdir()
|
|
|
- }
|
|
|
- }
|
|
|
- return this.tempDirectory
|
|
|
- }
|
|
|
-
|
|
|
getUploadToServer () {
|
|
|
if (process.type === 'browser') {
|
|
|
return binding.getUploadToServer()
|