fix: prevent sentry from loading when telemetry is disabled (#10543)

Co-authored-by: forehalo <forehalo@gmail.com>
This commit is contained in:
hackerESQ
2025-03-05 06:09:38 -06:00
committed by GitHub
parent b247b8e26c
commit fed0e0add3
16 changed files with 122 additions and 200 deletions
@@ -2,3 +2,4 @@
import './env';
import './public-path';
import './polyfill/browser';
import './telemetry';
@@ -2,3 +2,4 @@
import './env';
import './public-path';
import './polyfill/electron';
import './telemetry';
@@ -0,0 +1,4 @@
import { mixpanel, sentry } from '@affine/track';
mixpanel.init();
sentry.init();
@@ -1,4 +1,4 @@
import { enableAutoTrack, mixpanel } from '@affine/track';
import { enableAutoTrack, mixpanel, sentry } from '@affine/track';
import { appSettingAtom } from '@toeverything/infra';
import { useAtomValue } from 'jotai/react';
import { useLayoutEffect } from 'react';
@@ -7,9 +7,12 @@ export function Telemetry() {
const settings = useAtomValue(appSettingAtom);
useLayoutEffect(() => {
if (settings.enableTelemetry === false) {
sentry.disable();
mixpanel.opt_out_tracking();
return;
} else {
sentry.enable();
mixpanel.opt_in_tracking();
return enableAutoTrack(document.body, mixpanel.track);
}
}, [settings.enableTelemetry]);
@@ -8,7 +8,6 @@ import { useAppUpdater } from '@affine/core/components/hooks/use-app-updater';
import { UrlService } from '@affine/core/modules/url';
import { appIconMap, appNames } from '@affine/core/utils/channel';
import { useI18n } from '@affine/i18n';
import { mixpanel } from '@affine/track';
import { ArrowRightSmallIcon, OpenInNewIcon } from '@blocksuite/icons/rc';
import { useServices } from '@toeverything/infra';
import { useCallback } from 'react';
@@ -47,11 +46,6 @@ export const AboutAffine = () => {
const onSwitchTelemetry = useCallback(
(checked: boolean) => {
if (!checked) {
mixpanel.opt_out_tracking();
} else {
mixpanel.opt_in_tracking();
}
updateSettings('enableTelemetry', checked);
},
[updateSettings]