Add crashRepoter.getLastCrashReport API
This commit is contained in:
parent
9a825c5cbd
commit
66e96f69fc
1 changed files with 26 additions and 7 deletions
|
@ -1,18 +1,21 @@
|
||||||
{spawn} = require 'child_process'
|
|
||||||
binding = process.atomBinding 'crash_reporter'
|
binding = process.atomBinding 'crash_reporter'
|
||||||
|
fs = require 'fs'
|
||||||
|
os = require 'os'
|
||||||
|
path = require 'path'
|
||||||
|
{spawn} = require 'child_process'
|
||||||
|
|
||||||
class CrashReporter
|
class CrashReporter
|
||||||
start: (options={}) ->
|
start: (options={}) ->
|
||||||
{productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options
|
{@productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options
|
||||||
|
|
||||||
productName ?= 'Atom-Shell'
|
@productName ?= 'Atom-Shell'
|
||||||
companyName ?= 'GitHub, Inc'
|
companyName ?= 'GitHub, Inc'
|
||||||
submitUrl ?= 'http://54.249.141.255:1127/post'
|
submitUrl ?= 'http://54.249.141.255:1127/post'
|
||||||
autoSubmit ?= true
|
autoSubmit ?= true
|
||||||
ignoreSystemCrashHandler ?= false
|
ignoreSystemCrashHandler ?= false
|
||||||
extra ?= {}
|
extra ?= {}
|
||||||
|
|
||||||
extra._productName ?= productName
|
extra._productName ?= @productName
|
||||||
extra._companyName ?= companyName
|
extra._companyName ?= companyName
|
||||||
extra._version ?=
|
extra._version ?=
|
||||||
if process.type is 'browser'
|
if process.type is 'browser'
|
||||||
|
@ -20,12 +23,12 @@ class CrashReporter
|
||||||
else
|
else
|
||||||
require('remote').require('app').getVersion()
|
require('remote').require('app').getVersion()
|
||||||
|
|
||||||
start = -> binding.start productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra
|
start = => binding.start @productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra
|
||||||
|
|
||||||
if process.platform is 'win32'
|
if process.platform is 'win32'
|
||||||
args = [
|
args = [
|
||||||
"--reporter-url=#{submitUrl}"
|
"--reporter-url=#{submitUrl}"
|
||||||
"--application-name=#{productName}"
|
"--application-name=#{@productName}"
|
||||||
"--v=1"
|
"--v=1"
|
||||||
]
|
]
|
||||||
env = ATOM_SHELL_INTERNAL_CRASH_SERVICE: 1
|
env = ATOM_SHELL_INTERNAL_CRASH_SERVICE: 1
|
||||||
|
@ -35,4 +38,20 @@ class CrashReporter
|
||||||
else
|
else
|
||||||
start()
|
start()
|
||||||
|
|
||||||
module.exports = new CrashReporter
|
getLastCrashReport: ->
|
||||||
|
tmpdir =
|
||||||
|
if process.platform is 'win32'
|
||||||
|
os.tmpdir()
|
||||||
|
else
|
||||||
|
'/tmp'
|
||||||
|
log = path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
|
||||||
|
try
|
||||||
|
reports = String(fs.readFileSync(log)).split('\n')
|
||||||
|
return null unless reports.length > 1
|
||||||
|
[time, id] = reports[reports.length - 2].split ','
|
||||||
|
return {date: new Date(parseInt(time) * 1000), id}
|
||||||
|
catch e
|
||||||
|
return null
|
||||||
|
|
||||||
|
crashRepoter = new CrashReporter
|
||||||
|
module.exports = crashRepoter
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue