Guard against app.getPath throwing with OS fallback
This commit is contained in:
parent
fbbffe03a5
commit
16e3991ffa
1 changed files with 12 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const {spawn} = require('child_process')
|
||||
const os = require('os')
|
||||
const electron = require('electron')
|
||||
const {app} = process.type === 'browser' ? electron : electron.remote
|
||||
const binding = process.atomBinding('crash_reporter')
|
||||
|
@ -13,7 +14,7 @@ class CrashReporter {
|
|||
this.productName = options.productName
|
||||
let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options
|
||||
|
||||
this.tempDirectory = app.getPath('temp')
|
||||
this.tempDirectory = getTempPath()
|
||||
if (this.productName == null) {
|
||||
this.productName = app.getName()
|
||||
}
|
||||
|
@ -72,9 +73,18 @@ class CrashReporter {
|
|||
|
||||
getUploadedReports () {
|
||||
const productName = this.productName != null ? this.productName : app.getName()
|
||||
const tempDirectory = this.tempDirectory != null ? this.tempDirectory : app.getPath('temp')
|
||||
const tempDirectory = this.tempDirectory != null ? this.tempDirectory : getTempPath()
|
||||
return binding._getUploadedReports(productName, tempDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
const getTempPath = () => {
|
||||
try {
|
||||
return app.getPath('temp')
|
||||
} catch (error) {
|
||||
// app.getPath may throw so fallback to OS temp directory
|
||||
return os.tmpdir()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CrashReporter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue