electron/atom/common/api/lib/crash-reporter.coffee

67 lines
1.8 KiB
CoffeeScript
Raw Normal View History

fs = require 'fs'
os = require 'os'
path = require 'path'
{spawn} = require 'child_process'
2015-11-13 08:03:40 +00:00
electron = require 'electron'
binding = process.atomBinding 'crash_reporter'
class CrashReporter
start: (options={}) ->
2015-11-13 08:03:40 +00:00
{@productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra} = options
# Deprecated.
{deprecate} = electron
if options.submitUrl
submitURL ?= options.submitUrl
deprecate.warn 'submitUrl', 'submitURL'
{app} = if process.type is 'browser' then electron else electron.remote
@productName ?= app.getName()
companyName ?= 'GitHub, Inc'
2015-11-13 08:03:40 +00:00
submitURL ?= 'http://54.249.141.255:1127/post'
autoSubmit ?= true
ignoreSystemCrashHandler ?= false
extra ?= {}
extra._productName ?= @productName
extra._companyName ?= companyName
extra._version ?= app.getVersion()
2015-11-13 08:03:40 +00:00
start = => binding.start @productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra
2014-02-26 12:58:17 +00:00
if process.platform is 'win32'
args = [
2015-11-13 08:03:40 +00:00
"--reporter-url=#{submitURL}"
"--application-name=#{@productName}"
"--v=1"
]
env = ATOM_SHELL_INTERNAL_CRASH_SERVICE: 1
spawn process.execPath, args, {env, detached: true}
start()
2014-02-26 12:58:17 +00:00
else
start()
getLastCrashReport: ->
reports = this.getUploadedReports()
if reports.length > 0 then reports[0] else null
getUploadedReports: ->
tmpdir =
if process.platform is 'win32'
os.tmpdir()
else
'/tmp'
log =
if process.platform is 'darwin'
path.join tmpdir, "#{@productName} Crashes"
else
path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
2015-06-06 09:59:20 +00:00
binding._getUploadedReports log
crashRepoter = new CrashReporter
module.exports = crashRepoter