🎨 Use ES6 class, destructuring, and let/const

This commit is contained in:
Kevin Sawicki 2016-10-05 13:40:39 -07:00
parent ac0658bbf1
commit f282b51c98
2 changed files with 17 additions and 31 deletions

View file

@ -1,27 +1,18 @@
'use strict' 'use strict'
const os = require('os') const {spawn} = require('child_process')
const path = require('path')
const spawn = require('child_process').spawn
const electron = require('electron') const electron = require('electron')
const binding = process.atomBinding('crash_reporter') const binding = process.atomBinding('crash_reporter')
var CrashReporter = (function () { class CrashReporter {
function CrashReporter () {} start (options) {
CrashReporter.prototype.start = function (options) {
var app, args, autoSubmit, companyName, env, extra, ignoreSystemCrashHandler, start, submitURL
if (options == null) { if (options == null) {
options = {} options = {}
} }
this.productName = options.productName this.productName = options.productName
companyName = options.companyName let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options
submitURL = options.submitURL
autoSubmit = options.autoSubmit
ignoreSystemCrashHandler = options.ignoreSystemCrashHandler
extra = options.extra
app = (process.type === 'browser' ? electron : electron.remote).app const app = (process.type === 'browser' ? electron : electron.remote).app
if (this.productName == null) { if (this.productName == null) {
this.productName = app.getName() this.productName = app.getName()
} }
@ -43,18 +34,17 @@ var CrashReporter = (function () {
if (extra._version == null) { if (extra._version == null) {
extra._version = app.getVersion() extra._version = app.getVersion()
} }
if (companyName == null) { if (companyName == null) {
throw new Error('companyName is a required option to crashReporter.start') throw new Error('companyName is a required option to crashReporter.start')
} }
if (submitURL == null) { if (submitURL == null) {
throw new Error('submitURL is a required option to crashReporter.start') throw new Error('submitURL is a required option to crashReporter.start')
} }
start = () => {
binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)
}
if (process.platform === 'win32') { if (process.platform === 'win32') {
args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1'] const args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1']
env = { const env = {
ELECTRON_INTERNAL_CRASH_SERVICE: 1 ELECTRON_INTERNAL_CRASH_SERVICE: 1
} }
spawn(process.execPath, args, { spawn(process.execPath, args, {
@ -62,12 +52,12 @@ var CrashReporter = (function () {
detached: true detached: true
}) })
} }
return start()
binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra)
} }
CrashReporter.prototype.getLastCrashReport = function () { getLastCrashReport () {
var reports const reports = this.getUploadedReports()
reports = this.getUploadedReports()
if (reports.length > 0) { if (reports.length > 0) {
return reports[0] return reports[0]
} else { } else {
@ -75,11 +65,9 @@ var CrashReporter = (function () {
} }
} }
CrashReporter.prototype.getUploadedReports = function () { getUploadedReports () {
return binding._getUploadedReports(this.productName) return binding._getUploadedReports(this.productName)
} }
}
return CrashReporter
})()
module.exports = new CrashReporter() module.exports = new CrashReporter()

View file

@ -5,10 +5,8 @@ const path = require('path')
const url = require('url') const url = require('url')
const {closeWindow} = require('./window-helpers') const {closeWindow} = require('./window-helpers')
const remote = require('electron').remote const {remote} = require('electron')
const app = remote.require('electron').app const {app, BrowserWindow, crashReporter} = remote.require('electron')
const crashReporter = remote.require('electron').crashReporter
const BrowserWindow = remote.require('electron').BrowserWindow
describe('crashReporter module', function () { describe('crashReporter module', function () {
var fixtures = path.resolve(__dirname, 'fixtures') var fixtures = path.resolve(__dirname, 'fixtures')