crash-reporter-init.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict'
  2. const { app } = require('electron')
  3. const cp = require('child_process')
  4. const os = require('os')
  5. const path = require('path')
  6. const getTempDirectory = function () {
  7. try {
  8. return app.getPath('temp')
  9. } catch (error) {
  10. return os.tmpdir()
  11. }
  12. }
  13. exports.crashReporterInit = function (options) {
  14. const productName = options.productName || app.getName()
  15. const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`)
  16. let crashServicePid
  17. if (process.platform === 'win32') {
  18. const env = {
  19. ELECTRON_INTERNAL_CRASH_SERVICE: 1
  20. }
  21. const args = [
  22. '--reporter-url=' + options.submitURL,
  23. '--application-name=' + productName,
  24. '--crashes-directory=' + crashesDirectory,
  25. '--v=1'
  26. ]
  27. const crashServiceProcess = cp.spawn(process.helperExecPath, args, {
  28. env,
  29. detached: true
  30. })
  31. crashServicePid = crashServiceProcess.pid
  32. }
  33. return {
  34. productName,
  35. crashesDirectory,
  36. crashServicePid,
  37. appVersion: app.getVersion()
  38. }
  39. }