From 80bc63bb90162c2a720c59406a71c37e0d212ab3 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Thu, 2 May 2024 15:52:53 -0400 Subject: [PATCH] Disable crash reporting in production --- app/crashReports.ts | 24 +++++++++++++++++++++--- app/main.ts | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/crashReports.ts b/app/crashReports.ts index c6181f5ab5..0a8d211f0d 100644 --- a/app/crashReports.ts +++ b/app/crashReports.ts @@ -9,6 +9,7 @@ import z from 'zod'; import type { LoggerType } from '../ts/types/Logging'; import * as Errors from '../ts/types/errors'; +import { isProduction } from '../ts/util/version'; import OS from '../ts/util/os/osMain'; const dumpSchema = z @@ -64,12 +65,21 @@ async function eraseDumps( export function setup( getLogger: () => LoggerType, - showDebugLogWindow: () => Promise + showDebugLogWindow: () => Promise, + forceEnable = false ): void { - getLogger().info('crashReporter: enabled'); - crashReporter.start({ uploadToServer: false }); + const isEnabled = !isProduction(app.getVersion()) || forceEnable; + + if (isEnabled) { + getLogger().info(`crashReporter: ${forceEnable ? 'force ' : ''}enabled`); + crashReporter.start({ uploadToServer: false }); + } ipc.handle('crash-reports:get-count', async () => { + if (!isEnabled) { + return 0; + } + const pendingDumps = await getPendingDumps(); if (pendingDumps.length !== 0) { getLogger().warn( @@ -80,6 +90,10 @@ export function setup( }); ipc.handle('crash-reports:write-to-log', async () => { + if (!isEnabled) { + return; + } + const pendingDumps = await getPendingDumps(); if (pendingDumps.length === 0) { return; @@ -119,6 +133,10 @@ export function setup( }); ipc.handle('crash-reports:erase', async () => { + if (!isEnabled) { + return; + } + const pendingDumps = await getPendingDumps(); await eraseDumps(getLogger(), pendingDumps); diff --git a/app/main.ts b/app/main.ts index 7f8406c2fc..26d56b4780 100644 --- a/app/main.ts +++ b/app/main.ts @@ -208,10 +208,13 @@ const DISABLE_GPU = OS.isLinux() && !process.argv.some(arg => arg === '--enable-gpu'); const DISABLE_IPV6 = process.argv.some(arg => arg === '--disable-ipv6'); +const FORCE_ENABLE_CRASH_REPORTS = process.argv.some( + arg => arg === '--enable-crash-reports' +); const CLI_LANG = cliOptions.lang as string | undefined; -setupCrashReports(getLogger, showDebugLogWindow); +setupCrashReports(getLogger, showDebugLogWindow, FORCE_ENABLE_CRASH_REPORTS); let sendDummyKeystroke: undefined | (() => void); if (OS.isWindows()) {