Skip to content

Commit

Permalink
fix: remove crashReporterRenderer.sendSync() workaround for init() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and MarshallOfSound committed Mar 19, 2019
1 parent 6c4ee66 commit 61d1df2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 64 deletions.
1 change: 1 addition & 0 deletions filenames.gni
Expand Up @@ -41,6 +41,7 @@ filenames = {
"lib/browser/api/web-contents.js",
"lib/browser/api/web-contents-view.js",
"lib/browser/chrome-extension.js",
"lib/browser/crash-reporter-init.js",
"lib/browser/guest-view-manager.js",
"lib/browser/guest-window-manager.js",
"lib/browser/init.js",
Expand Down
8 changes: 3 additions & 5 deletions lib/browser/api/crash-reporter.js
@@ -1,13 +1,11 @@
'use strict'

const CrashReporter = require('@electron/internal/common/crash-reporter')
const ipcMain = require('@electron/internal/browser/ipc-main-internal')
const { crashReporterInit } = require('@electron/internal/browser/crash-reporter-init')

class CrashReporterMain extends CrashReporter {
sendSync (channel, ...args) {
const event = {}
ipcMain.emit(channel, event, ...args)
return event.returnValue
init (options) {
return crashReporterInit(options)
}
}

Expand Down
46 changes: 46 additions & 0 deletions lib/browser/crash-reporter-init.js
@@ -0,0 +1,46 @@
'use strict'

const { app } = require('electron')
const cp = require('child_process')
const os = require('os')
const path = require('path')

const getTempDirectory = function () {
try {
return app.getPath('temp')
} catch (error) {
return os.tmpdir()
}
}

exports.crashReporterInit = function (options) {
const productName = options.productName || app.getName()
const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`)
let crashServicePid

if (process.platform === 'win32') {
const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
}
const args = [
'--reporter-url=' + options.submitURL,
'--application-name=' + productName,
'--crashes-directory=' + crashesDirectory,
'--v=1'
]

const crashServiceProcess = cp.spawn(process.helperExecPath, args, {
env,
detached: true
})

crashServicePid = crashServiceProcess.pid
}

return {
productName,
crashesDirectory,
crashServicePid,
appVersion: app.getVersion()
}
}
44 changes: 1 addition & 43 deletions lib/browser/rpc-server.js
@@ -1,16 +1,14 @@
'use strict'

const { spawn } = require('child_process')
const electron = require('electron')
const { EventEmitter } = require('events')
const fs = require('fs')
const os = require('os')
const path = require('path')
const v8Util = process.atomBinding('v8_util')
const eventBinding = process.atomBinding('event')

const { isPromise } = electron

const { crashReporterInit } = require('@electron/internal/browser/crash-reporter-init')
const ipcMain = require('@electron/internal/browser/ipc-main-internal')
const objectsRegistry = require('@electron/internal/browser/objects-registry')
const guestViewManager = require('@electron/internal/browser/guest-view-manager')
Expand Down Expand Up @@ -468,46 +466,6 @@ ipcMain.on('ELECTRON_BROWSER_WINDOW_CLOSE', function (event) {
event.returnValue = null
})

const getTempDirectory = function () {
try {
return electron.app.getPath('temp')
} catch (error) {
return os.tmpdir()
}
}

const crashReporterInit = function (options) {
const productName = options.productName || electron.app.getName()
const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`)
let crashServicePid

if (process.platform === 'win32') {
const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1
}
const args = [
'--reporter-url=' + options.submitURL,
'--application-name=' + productName,
'--crashes-directory=' + crashesDirectory,
'--v=1'
]

const crashServiceProcess = spawn(process.helperExecPath, args, {
env,
detached: true
})

crashServicePid = crashServiceProcess.pid
}

return {
productName,
crashesDirectory,
crashServicePid,
appVersion: electron.app.getVersion()
}
}

const setReturnValue = function (event, getValue) {
try {
event.returnValue = [null, getValue()]
Expand Down
16 changes: 2 additions & 14 deletions lib/common/crash-reporter.js
Expand Up @@ -2,28 +2,16 @@

const binding = process.atomBinding('crash_reporter')

const errorUtils = require('@electron/internal/common/error-utils')

class CrashReporter {
contructor () {
this.productName = null
this.crashesDirectory = null
}

sendSync (channel, ...args) {
init (options) {
throw new Error('Not implemented')
}

invoke (command, ...args) {
const [ error, result ] = this.sendSync(command, ...args)

if (error) {
throw errorUtils.deserialize(error)
}

return result
}

start (options) {
if (options == null) options = {}

Expand Down Expand Up @@ -51,7 +39,7 @@ class CrashReporter {
throw new Error('submitURL is a required option to crashReporter.start')
}

const ret = this.invoke('ELECTRON_CRASH_REPORTER_INIT', {
const ret = this.init({
submitURL,
productName
})
Expand Down
15 changes: 13 additions & 2 deletions lib/renderer/api/crash-reporter.js
Expand Up @@ -2,10 +2,21 @@

const CrashReporter = require('@electron/internal/common/crash-reporter')
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const errorUtils = require('@electron/internal/common/error-utils')

const invoke = function (command, ...args) {
const [ error, result ] = ipcRenderer.sendSync(command, ...args)

if (error) {
throw errorUtils.deserialize(error)
}

return result
}

class CrashReporterRenderer extends CrashReporter {
sendSync (channel, ...args) {
return ipcRenderer.sendSync(channel, ...args)
init (options) {
return invoke('ELECTRON_CRASH_REPORTER_INIT', options)
}
}

Expand Down

0 comments on commit 61d1df2

Please sign in to comment.