From 9ca0e73cccafe6a84dfa99310a474871168d2a9b Mon Sep 17 00:00:00 2001 From: ggichure Date: Wed, 15 May 2024 20:01:58 +0300 Subject: [PATCH 1/2] Error and crash reporting --- CHANGELOG.md | 1 + lib/l10n/app_en.arb | 10 +++++ lib/main.dart | 8 +++- lib/routes.dart | 4 +- lib/settings/pages/debug_settings_page.dart | 44 +++++++++++++++++++++ pubspec.lock | 40 +++++++++++++++++++ pubspec.yaml | 1 + 7 files changed, 105 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 859157439..d1878ac3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Setting to use colorized usernames - contribution from @ggichure. - Show the number of new comments a read post has received since last visited - Added ability to mark read on scroll - contribution from @Fmstrat +- Added Error and crash reporting using a logs.txt- contribution from @ggichure ## Changed - Small UI adjustments for account switcher diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 44e23e1e9..a7f96e299 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -447,6 +447,12 @@ "@countUsers": { "description": "Describes a certain number of users" }, + "crashReports": "Crash Reports", + "@crashReports": { + "description": "Initiates the process of sending a crash report to developers." + }, + "crashReportsView": "View Crash Reports", + "@crashReportsView": {}, "createAccount": "Create Account", "@createAccount": {}, "createComment": "Create Comment", @@ -1515,6 +1521,10 @@ "@report": {}, "reportComment": "Report Comment", "@reportComment": {}, + "reportCrashLogsTooltip": "Inspect Crash Reports Before Sending to Developers", + "@reportCrashLogsTooltip": { + "description": "Provides the ability to review crash reports and their details before sending them to developers for analysis." + }, "reset": "Reset", "@reset": { "description": "Label for the reset button in Setting -> Appearance -> Posts/Comments" diff --git a/lib/main.dart b/lib/main.dart index 822e618f7..bfd56fc8a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'dart:io'; // Flutter imports +import 'package:catcher_2/catcher_2.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -70,7 +71,10 @@ Future initializeDatabase() async { void main() async { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); - +// catcher + String filePath = join((await getApplicationDocumentsDirectory()).path, 'thunder_log.txt'); + Catcher2Options debugOptions = Catcher2Options(SilentReportMode(), [FileHandler(File(filePath), printLogs: true)]); + Catcher2Options releaseOptions = Catcher2Options(SilentReportMode(), [FileHandler(File(filePath))]); // Setting SystemUIMode SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); @@ -90,7 +94,7 @@ void main() async { // Perform preference migrations await performSharedPreferencesMigration(); - runApp(const ThunderApp()); + Catcher2(rootWidget: const ThunderApp(), debugConfig: debugOptions, releaseConfig: releaseOptions); if (!kIsWeb && Platform.isAndroid) { // Set high refresh rate after app initialization diff --git a/lib/routes.dart b/lib/routes.dart index 880af3db9..4294e2a7a 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -1,3 +1,4 @@ +import 'package:catcher_2/catcher_2.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -24,6 +25,7 @@ import 'package:thunder/user/pages/user_settings_page.dart'; PageController thunderPageController = PageController(initialPage: 0); final GoRouter router = GoRouter( + navigatorKey: Catcher2.navigatorKey, debugLogDiagnostics: true, routes: [ GoRoute( @@ -35,7 +37,7 @@ final GoRouter router = GoRouter( GoRoute( name: 'settings', path: '/settings', - builder: (BuildContext context, GoRouterState state) => SettingsPage(), + builder: (BuildContext context, GoRouterState state) => const SettingsPage(), routes: [ GoRoute( name: 'general', diff --git a/lib/settings/pages/debug_settings_page.dart b/lib/settings/pages/debug_settings_page.dart index d12ac0814..cbb68d81b 100644 --- a/lib/settings/pages/debug_settings_page.dart +++ b/lib/settings/pages/debug_settings_page.dart @@ -192,6 +192,50 @@ class _DebugSettingsPageState extends State { }, ), ), + SliverToBoxAdapter( + child: Padding( + padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(l10n.crashReports, style: theme.textTheme.titleMedium), + const SizedBox(height: 8.0), + ], + ), + ), + ), + const SliverToBoxAdapter(child: SizedBox(height: 8.0)), + SliverToBoxAdapter( + child: SettingsListTile( + icon: Icons.bug_report, + subtitle: l10n.reportCrashLogsTooltip, + description: l10n.crashReportsView, + widget: Container(), + onTap: () async { + String filePath = join((await getApplicationDocumentsDirectory()).path, 'thunder_log.txt'); + final file = File(filePath); + + final contents = await file.readAsString(); + + if (context.mounted) { + await showThunderDialog( + context: context, + title: l10n.crashReports, + contentWidgetBuilder: (setPrimaryButtonEnabled) => SingleChildScrollView(child: Text(contents)), + primaryButtonText: l10n.copy, + primaryButtonInitialEnabled: true, + onPrimaryButtonPressed: (dialogContext, setPrimaryButtonEnabled) async { + await Clipboard.setData(ClipboardData(text: contents)); + if (context.mounted) dialogContext.pop(); + }, + secondaryButtonText: l10n.cancel, + onSecondaryButtonPressed: (dialogContext) => dialogContext.pop(), + ); + } + }, + ), + ), + const SliverToBoxAdapter(child: SizedBox(height: 8.0)), SliverToBoxAdapter( child: Padding( padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 8.0), diff --git a/pubspec.lock b/pubspec.lock index 21834bc08..8ec60edf8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -209,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + catcher_2: + dependency: "direct main" + description: + name: catcher_2 + sha256: "2c2c6f8cf8c817730cd1dbb010d55292396930e7a3d42c04c3039e3fd411a2f8" + url: "https://pub.dev" + source: hosted + version: "1.2.6" characters: dependency: transitive description: @@ -724,6 +732,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_mailer: + dependency: transitive + description: + name: flutter_mailer + sha256: "4fffaa35e911ff5ec2e5a4ebbca62c372e99a154eb3bb2c0bf79f09adf6ecf4c" + url: "https://pub.dev" + source: hosted + version: "2.1.2" flutter_markdown: dependency: "direct main" description: @@ -782,6 +798,14 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: transitive + description: + name: fluttertoast + sha256: "81b68579e23fcbcada2db3d50302813d2371664afe6165bc78148050ab94bf66" + url: "https://pub.dev" + source: hosted + version: "8.2.5" freezed_annotation: dependency: transitive description: @@ -1072,6 +1096,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + mailer: + dependency: transitive + description: + name: mailer + sha256: d25d89555c1031abacb448f07b801d7c01b4c21d4558e944b12b64394c84a3cb + url: "https://pub.dev" + source: hosted + version: "6.1.0" markdown: dependency: transitive description: @@ -1467,6 +1499,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + sentry: + dependency: transitive + description: + name: sentry + sha256: fd1fbfe860c05f5c52820ec4dbf2b6473789e83ead26cfc18bca4fe80bf3f008 + url: "https://pub.dev" + source: hosted + version: "8.2.0" share_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4549f8332..fad75332b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -109,6 +109,7 @@ dependencies: drift: ^2.16.0 sqlite3_flutter_libs: ^0.5.20 super_sliver_list: ^0.4.1 + catcher_2: ^1.2.6 dev_dependencies: build_runner: ^2.4.6 From 60c72da122c34d34b9006ec057031bbd93ed35ed Mon Sep 17 00:00:00 2001 From: ggichure Date: Wed, 28 Aug 2024 12:20:48 +0300 Subject: [PATCH 2/2] sort arb files --- lib/l10n/app_en.arb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 11fb515be..cdcbeeac7 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -523,14 +523,6 @@ "@countUsers": { "description": "Describes a certain number of users" }, - - "crashReports": "Crash Reports", - "@crashReports": { - "description": "Initiates the process of sending a crash report to developers." - }, - "crashReportsView": "View Crash Reports", - "@crashReportsView": {}, - "countUsersActiveDay": "{count} users/day", "@countUsersActiveDay": { "description": "Number of users active in the last day" @@ -547,6 +539,12 @@ "@countUsersActiveWeek": { "description": "Number of users active in the last week" }, + "crashReports": "Crash Reports", + "@crashReports": { + "description": "Initiates the process of sending a crash report to developers." + }, + "crashReportsView": "View Crash Reports", + "@crashReportsView": {}, "createAccount": "Create Account", "@createAccount": {}, "createComment": "Create Comment", @@ -1809,11 +1807,10 @@ "@report": {}, "reportComment": "Report Comment", "@reportComment": {}, - "reportCrashLogsTooltip": "Inspect Crash Reports Before Sending to Developers", "@reportCrashLogsTooltip": { "description": "Provides the ability to review crash reports and their details before sending them to developers for analysis." - }, + }, "reporter": "Reporter:", "@reporter": { "description": "Name of reporter that reported a post/comment"