From 841d5d57a2cbee35142964de116891609fce0f1c Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 17 May 2019 06:42:11 -0700 Subject: [PATCH] Enable desktop crash reporting Summary: Sends native crash reports for production internal builds. Reviewed By: passy Differential Revision: D15391757 fbshipit-source-id: a4149c2a264eb5ef38fb6f1cc43d52361ac83748 --- src/fb-stubs/constants.js | 2 ++ src/init.js | 3 ++ src/utils/electronCrashReporter.js | 50 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/utils/electronCrashReporter.js diff --git a/src/fb-stubs/constants.js b/src/fb-stubs/constants.js index 04796e3d6..35fcd8d51 100644 --- a/src/fb-stubs/constants.js +++ b/src/fb-stubs/constants.js @@ -20,3 +20,5 @@ export const INSIGHT_INTERN_APP_TOKEN = ''; // Enables the flipper data to be exported through shareabale link export const ENABLE_SHAREABLE_LINK = false; + +export const IS_PUBLIC_BUILD = true; diff --git a/src/init.js b/src/init.js index e8f2afc4f..055727877 100644 --- a/src/init.js +++ b/src/init.js @@ -20,6 +20,7 @@ import dispatcher from './dispatcher/index.js'; import TooltipProvider from './ui/components/TooltipProvider.js'; import config from './utils/processConfig.js'; import {initLauncherHooks} from './utils/launcher.js'; +import initCrashReporter from './utils/electronCrashReporter'; const path = require('path'); const store = createStore( @@ -59,6 +60,8 @@ function init() { .catch(console.error); initLauncherHooks(config(), store); + const sessionId = store.getState().application.sessionId; + initCrashReporter(sessionId || ''); } // make init function callable from outside diff --git a/src/utils/electronCrashReporter.js b/src/utils/electronCrashReporter.js new file mode 100644 index 000000000..79f2b6a63 --- /dev/null +++ b/src/utils/electronCrashReporter.js @@ -0,0 +1,50 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import {exists, mkdir} from 'fs'; +import {promisify} from 'util'; +import {crashReporter, remote} from 'electron'; +import isProduction from '../utils/isProduction.js'; +import {IS_PUBLIC_BUILD} from '../fb-stubs/constants'; +import {tmpName} from 'tmp'; +import {resolve} from 'path'; + +// Cross platform way to find the /tmp directory or equivalent. +// The tempPath set should be persistent across app restarts. +const tempPathPromise: Promise = promisify(tmpName)({ + template: '/tmp/tmp-XXXXXX', +}).then(name => resolve(name, '..', 'flipper')); + +export default function initCrashReporter(sessionId: string): Promise { + const flipperVersion = remote.app.getVersion(); + return tempPathPromise.then(tempPath => { + return promisify(exists)(tempPath) + .then(pathExists => { + if (!pathExists) { + return promisify(mkdir)(tempPath); + } + return Promise.resolve(); + }) + .then(() => { + remote.app.setPath('temp', tempPath); + const electronCrashReporterArgs = { + productName: 'Flipper', + companyName: 'Facebook', + submitURL: 'https://www.facebook.com/intern/flipper/crash_upload', + uploadToServer: isProduction() && !IS_PUBLIC_BUILD, + ignoreSystemCrashHandler: true, + extra: { + flipper_version: flipperVersion, + session_id: sessionId, + }, + }; + remote.crashReporter.start(electronCrashReporterArgs); + crashReporter.start(electronCrashReporterArgs); + remote.process.crash(); + }); + }); +}