Add setting to opt out of crash reporting (#1312)
This commit is contained in:
commit
5119e7a336
5 changed files with 56 additions and 3 deletions
|
@ -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<String> 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<void> 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<void> setShouldReportCrashes(bool value) {
|
||||
return _preferences.setBool(keyShouldReportCrashes, value);
|
||||
}
|
||||
|
||||
/// The log file currently in use.
|
||||
static File? logFile;
|
||||
|
||||
|
|
2
lib/generated/intl/messages_en.dart
generated
2
lib/generated/intl/messages_en.dart
generated
|
@ -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(
|
||||
|
|
11
lib/generated/l10n.dart
generated
11
lib/generated/l10n.dart
generated
|
@ -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<S> {
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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<AdvancedSettingsScreen> {
|
|||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
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(),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Add table
Reference in a new issue