mirror of
https://github.com/electron/electron.git
synced 2026-01-25 23:38:18 -05:00
Guard against app.getPath throwing with OS fallback
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user