From 4fb7113593ca49d839126f2d6ba3a8aa0f3bc6cf Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Tue, 6 Jul 2021 11:13:45 +0300 Subject: [PATCH] Add UI to disable Sentry Signed-off-by: Hung-Han (Henry) Chen --- src/common/user-store/preferences-helpers.ts | 14 +++++++++++++ src/common/user-store/user-store.ts | 3 +++ src/main/index.ts | 7 +++++++ .../components/+preferences/preferences.tsx | 20 +++++++++++++++++++ src/renderer/lens-app.tsx | 8 ++++++++ 5 files changed, 52 insertions(+) diff --git a/src/common/user-store/preferences-helpers.ts b/src/common/user-store/preferences-helpers.ts index b35f7ddc51..3d205cd380 100644 --- a/src/common/user-store/preferences-helpers.ts +++ b/src/common/user-store/preferences-helpers.ts @@ -106,6 +106,19 @@ const allowTelemetry: PreferenceDescription = { }, }; +const allowErrorReporting: PreferenceDescription = { + fromStore(val) { + return val ?? true; + }, + toStore(val) { + if (val === true) { + return undefined; + } + + return val; + }, +}; + const downloadMirror: PreferenceDescription = { fromStore(val) { return val ?? "default"; @@ -227,6 +240,7 @@ export const DESCRIPTORS = { localeTimezone, allowUntrustedCAs, allowTelemetry, + allowErrorReporting, downloadMirror, downloadKubectlBinaries, downloadBinariesPath, diff --git a/src/common/user-store/user-store.ts b/src/common/user-store/user-store.ts index 9aa814890f..beeb2078e1 100644 --- a/src/common/user-store/user-store.ts +++ b/src/common/user-store/user-store.ts @@ -59,6 +59,7 @@ export class UserStore extends BaseStore /* implements UserStore @observable seenContexts = observable.set(); @observable newContexts = observable.set(); @observable allowTelemetry: boolean; + @observable allowErrorReporting: boolean; @observable allowUntrustedCAs: boolean; @observable colorTheme: string; @observable localeTimezone: string; @@ -169,6 +170,7 @@ export class UserStore extends BaseStore /* implements UserStore this.localeTimezone = DESCRIPTORS.localeTimezone.fromStore(preferences?.localeTimezone); this.allowUntrustedCAs = DESCRIPTORS.allowUntrustedCAs.fromStore(preferences?.allowUntrustedCAs); this.allowTelemetry = DESCRIPTORS.allowTelemetry.fromStore(preferences?.allowTelemetry); + this.allowErrorReporting = DESCRIPTORS.allowErrorReporting.fromStore(preferences?.allowErrorReporting); this.downloadMirror = DESCRIPTORS.downloadMirror.fromStore(preferences?.downloadMirror); this.downloadKubectlBinaries = DESCRIPTORS.downloadKubectlBinaries.fromStore(preferences?.downloadKubectlBinaries); this.downloadBinariesPath = DESCRIPTORS.downloadBinariesPath.fromStore(preferences?.downloadBinariesPath); @@ -188,6 +190,7 @@ export class UserStore extends BaseStore /* implements UserStore localeTimezone: DESCRIPTORS.localeTimezone.toStore(this.localeTimezone), allowUntrustedCAs: DESCRIPTORS.allowUntrustedCAs.toStore(this.allowUntrustedCAs), allowTelemetry: DESCRIPTORS.allowTelemetry.toStore(this.allowTelemetry), + allowErrorReporting: DESCRIPTORS.allowErrorReporting.toStore(this.allowErrorReporting), downloadMirror: DESCRIPTORS.downloadMirror.toStore(this.downloadMirror), downloadKubectlBinaries: DESCRIPTORS.downloadKubectlBinaries.toStore(this.downloadKubectlBinaries), downloadBinariesPath: DESCRIPTORS.downloadBinariesPath.toStore(this.downloadBinariesPath), diff --git a/src/main/index.ts b/src/main/index.ts index 6b04a8f4a8..188f3ceca0 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -63,6 +63,13 @@ import { CaptureConsole, Dedupe, Offline } from "@sentry/integrations"; import * as Sentry from "@sentry/electron/dist/main"; Sentry.init({ + beforeSend(event) { + const allow = UserStore.getInstance().allowErrorReporting; + + if (allow) return event; + + return null; + }, dsn, integrations: [ new CaptureConsole({ levels: ["error"] }), diff --git a/src/renderer/components/+preferences/preferences.tsx b/src/renderer/components/+preferences/preferences.tsx index 9bf82f9e4f..61f6554d4b 100644 --- a/src/renderer/components/+preferences/preferences.tsx +++ b/src/renderer/components/+preferences/preferences.tsx @@ -40,6 +40,7 @@ import { Tab, Tabs } from "../tabs"; import { FormSwitch, Switcher } from "../switch"; import { KubeconfigSyncs } from "./kubeconfig-syncs"; import { SettingLayout } from "../layout/setting-layout"; +import { Checkbox } from "../checkbox"; enum Pages { Application = "application", @@ -257,6 +258,25 @@ export class Preferences extends React.Component {

Telemetry

{telemetryExtensions.map(this.renderExtension)} + +
+ + { + UserStore.getInstance().allowErrorReporting = value; + }} + /> +
+ + Automatic error reports provide vital information about issues and application crashes. + It is highly recommended to keep this feature enabled to ensure fast turnaround for issues you might encounter. + +
+
+
+
)} {this.activeTab == Pages.Extensions && ( diff --git a/src/renderer/lens-app.tsx b/src/renderer/lens-app.tsx index aaa321e654..a82b0d0f57 100644 --- a/src/renderer/lens-app.tsx +++ b/src/renderer/lens-app.tsx @@ -39,8 +39,16 @@ import { catalogEntityRegistry } from "./api/catalog-entity-registry"; import { dsn, isProduction } from "../common/vars"; import { CaptureConsole, Dedupe, Offline } from "@sentry/integrations"; import * as Sentry from "@sentry/electron/dist/renderer"; +import { UserStore } from "../common/user-store"; Sentry.init({ + beforeSend(event) { + const allow = UserStore.getInstance().allowErrorReporting; + + if (allow) return event; + + return null; + }, dsn, integrations: [ new CaptureConsole({ levels: ["error"] }),