From 7761b32ab2575d36a9ed89e1b10f8aebf809fcba Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Fri, 11 Aug 2023 16:57:00 +0530 Subject: [PATCH] Add setting to opt out of crash reporting --- lib/core/error-reporting/super_logging.dart | 23 ++++++++++++++++++- lib/generated/intl/messages_en.dart | 2 ++ lib/generated/l10n.dart | 11 ++++++++- lib/l10n/intl_en.arb | 3 ++- lib/ui/settings/advanced_settings_screen.dart | 20 ++++++++++++++++ 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/core/error-reporting/super_logging.dart b/lib/core/error-reporting/super_logging.dart index a45c0fa4d..a4c8b6189 100644 --- a/lib/core/error-reporting/super_logging.dart +++ b/lib/core/error-reporting/super_logging.dart @@ -16,6 +16,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:photos/core/error-reporting/tunneled_transport.dart'; import 'package:photos/models/typedefs.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; +import 'package:shared_preferences/shared_preferences.dart'; extension SuperString on String { Iterable chunked(int chunkSize) sync* { @@ -141,11 +142,16 @@ class SuperLogging { /// The current super logging configuration static late LogConfig config; + static late SharedPreferences _preferences; + + static const keyShouldReportCrashes = "should_report_crashes"; + static Future main([LogConfig? appConfig]) async { appConfig ??= LogConfig(); SuperLogging.config = appConfig; WidgetsFlutterBinding.ensureInitialized(); + _preferences = await SharedPreferences.getInstance(); appVersion ??= await getAppVersion(); final isFDroidClient = await isFDroidBuild(); @@ -155,7 +161,10 @@ class SuperLogging { } final enable = appConfig.enableInDebugMode || kReleaseMode; - sentryIsEnabled = enable && appConfig.sentryDsn != null && !isFDroidClient; + sentryIsEnabled = enable && + appConfig.sentryDsn != null && + !isFDroidClient && + shouldReportCrashes(); fileIsEnabled = enable && appConfig.logDirPath != null; if (fileIsEnabled) { @@ -307,6 +316,18 @@ class SuperLogging { sentryQueueControl.add(error); } + static bool shouldReportCrashes() { + if (_preferences.containsKey(keyShouldReportCrashes)) { + return _preferences.getBool(keyShouldReportCrashes)!; + } else { + return true; // Report crashes by default + } + } + + static Future setShouldReportCrashes(bool value) { + return _preferences.setBool(keyShouldReportCrashes, value); + } + /// The log file currently in use. static File? logFile; diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 8b7260076..6901712ce 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -445,6 +445,8 @@ class MessageLookup extends MessageLookupByLibrary { "couldNotUpdateSubscription": MessageLookupByLibrary.simpleMessage( "Could not update subscription"), "count": MessageLookupByLibrary.simpleMessage("Count"), + "crashReporting": + MessageLookupByLibrary.simpleMessage("Crash reporting"), "create": MessageLookupByLibrary.simpleMessage("Create"), "createAccount": MessageLookupByLibrary.simpleMessage("Create account"), "createAlbumActionHint": MessageLookupByLibrary.simpleMessage( diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 687a253c9..4d62f1aec 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -1,7 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; - import 'intl/messages_all.dart'; // ************************************************************************** @@ -7585,6 +7584,16 @@ class S { args: [], ); } + + /// `Crash reporting` + String get crashReporting { + return Intl.message( + 'Crash reporting', + name: 'crashReporting', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 169f3509f..00a0c687c 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1094,5 +1094,6 @@ "sharedWithYou": "Shared with you", "sharedByYou": "Shared by you", "inviteYourFriendsToEnte": "Invite your friends to ente", - "failedToDownloadVideo": "Failed to download video" + "failedToDownloadVideo": "Failed to download video", + "crashReporting": "Crash reporting" } \ No newline at end of file diff --git a/lib/ui/settings/advanced_settings_screen.dart b/lib/ui/settings/advanced_settings_screen.dart index 94d6c9bd3..7e27da562 100644 --- a/lib/ui/settings/advanced_settings_screen.dart +++ b/lib/ui/settings/advanced_settings_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import "package:photos/core/error-reporting/super_logging.dart"; import "package:photos/generated/l10n.dart"; import "package:photos/services/user_remote_flag_service.dart"; import 'package:photos/theme/ente_theme.dart'; @@ -137,6 +138,25 @@ class _AdvancedSettingsScreenState extends State { ); }, ), + ), + const SizedBox( + height: 24, + ), + MenuItemWidget( + captionedTextWidget: CaptionedTextWidget( + title: S.of(context).crashReporting, + ), + menuItemColor: colorScheme.fillFaint, + singleBorderRadius: 8, + alignCaptionedTextToLeft: true, + trailingWidget: ToggleSwitchWidget( + value: () => SuperLogging.shouldReportCrashes(), + onChanged: () async { + await SuperLogging.setShouldReportCrashes( + !SuperLogging.shouldReportCrashes(), + ); + }, + ), ) ], ),