From f282b51c98a9a3170f6a6fd38603b14ed0cce0cc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 5 Oct 2016 13:40:39 -0700 Subject: [PATCH] :art: Use ES6 class, destructuring, and let/const --- lib/common/api/crash-reporter.js | 42 ++++++++++++-------------------- spec/api-crash-reporter-spec.js | 6 ++--- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 2ca645fc1053..fd7e30b702e6 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -1,27 +1,18 @@ 'use strict' -const os = require('os') -const path = require('path') -const spawn = require('child_process').spawn +const {spawn} = require('child_process') const electron = require('electron') const binding = process.atomBinding('crash_reporter') -var CrashReporter = (function () { - function CrashReporter () {} - - CrashReporter.prototype.start = function (options) { - var app, args, autoSubmit, companyName, env, extra, ignoreSystemCrashHandler, start, submitURL +class CrashReporter { + start (options) { if (options == null) { options = {} } this.productName = options.productName - companyName = options.companyName - submitURL = options.submitURL - autoSubmit = options.autoSubmit - ignoreSystemCrashHandler = options.ignoreSystemCrashHandler - extra = options.extra + let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options - app = (process.type === 'browser' ? electron : electron.remote).app + const app = (process.type === 'browser' ? electron : electron.remote).app if (this.productName == null) { this.productName = app.getName() } @@ -43,18 +34,17 @@ var CrashReporter = (function () { if (extra._version == null) { extra._version = app.getVersion() } + 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') } - start = () => { - binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra) - } + if (process.platform === 'win32') { - args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1'] - env = { + const args = ['--reporter-url=' + submitURL, '--application-name=' + this.productName, '--v=1'] + const env = { ELECTRON_INTERNAL_CRASH_SERVICE: 1 } spawn(process.execPath, args, { @@ -62,12 +52,12 @@ var CrashReporter = (function () { detached: true }) } - return start() + + binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra) } - CrashReporter.prototype.getLastCrashReport = function () { - var reports - reports = this.getUploadedReports() + getLastCrashReport () { + const reports = this.getUploadedReports() if (reports.length > 0) { return reports[0] } else { @@ -75,11 +65,9 @@ var CrashReporter = (function () { } } - CrashReporter.prototype.getUploadedReports = function () { + getUploadedReports () { return binding._getUploadedReports(this.productName) } - - return CrashReporter -})() +} module.exports = new CrashReporter() diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 286b7d2f6368..1c8e9c2c76d3 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -5,10 +5,8 @@ const path = require('path') const url = require('url') const {closeWindow} = require('./window-helpers') -const remote = require('electron').remote -const app = remote.require('electron').app -const crashReporter = remote.require('electron').crashReporter -const BrowserWindow = remote.require('electron').BrowserWindow +const {remote} = require('electron') +const {app, BrowserWindow, crashReporter} = remote.require('electron') describe('crashReporter module', function () { var fixtures = path.resolve(__dirname, 'fixtures')