diff --git a/lib/screens/MainScreens/mainMenu.dart b/lib/screens/MainScreens/mainMenu.dart index fbdf973..256575c 100644 --- a/lib/screens/MainScreens/mainMenu.dart +++ b/lib/screens/MainScreens/mainMenu.dart @@ -67,6 +67,7 @@ class _MainMenuState extends State { } bool force = false; + SharedPreferences? prefs; Future _fetchPage(int pageKey) async { logger.i('pageKey: $pageKey'); @@ -91,13 +92,17 @@ class _MainMenuState extends State { } } + Future getSharedPrefs() async { + prefs = await SharedPreferences.getInstance(); + } + @override void initState() { _pagingController.addPageRequestListener((pageKey) { _fetchPage(pageKey); }); super.initState(); - // fetchCategories(); + getSharedPrefs().then((value) => setUseSentry()); } // dispose @@ -106,6 +111,49 @@ class _MainMenuState extends State { super.dispose(); } + bool useSentryNull() { + return prefs?.getBool("useSentry") == null; + } + + Future setUseSentry() async { + if (useSentryNull()) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text( + AppLocalizations.of(context)?.useSentry ?? "Use Sentry", + ), + content: Text(AppLocalizations.of(context)?.sentryExplanation ?? + "Enable Sentry logging to quickly diagnose and fix issues! This provides us with real-time error tracking without compromising your privacy. Please help support JellyBook's development by turning on logging."), + actions: [ + TextButton( + onPressed: () { + prefs?.setBool("useSentry", true); + Navigator.of(context).pop(); + // crash app + throw Exception('Test Sentry'); + }, + child: Text( + AppLocalizations.of(context)?.yes ?? "Yes", + ), + ), + TextButton( + onPressed: () { + prefs?.setBool("useSentry", false); + Navigator.of(context).pop(); + }, + child: Text( + AppLocalizations.of(context)?.no ?? "No", + ), + ), + ], + ); + }, + ); + } + } + // should be a futureBuilder @override Widget build(BuildContext context) { diff --git a/lib/screens/MainScreens/settingsScreen.dart b/lib/screens/MainScreens/settingsScreen.dart index b64f4b4..abfc90b 100644 --- a/lib/screens/MainScreens/settingsScreen.dart +++ b/lib/screens/MainScreens/settingsScreen.dart @@ -174,6 +174,15 @@ class _SettingsScreenState extends State { const SizedBox( height: 20, ), + FutureBuilder( + future: useSentrySettings(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + return snapshot.data ?? Container(); + }, + ), + const SizedBox( + height: 20, + ), // experimentalFeaturesSettings(), // button to show log file // logToFile(), @@ -720,4 +729,22 @@ class _SettingsScreenState extends State { ); }, ); + + // useSentry settings + Future useSentrySettings() async => SettingsItem( + // settingKey: 'useSentry', + title: AppLocalizations.of(context)?.useSentry ?? 'Use Sentry', + selected: prefs?.getBool('useSentry').toString() ?? 'false', + backgroundColor: Theme.of(context).splashColor, + icon: Icons.bug_report, + values: { + 'true': AppLocalizations.of(context)?.yes ?? 'Yes', + 'false': AppLocalizations.of(context)?.no ?? 'No', + }, + onChange: (value) async { + debugPrint(value); + prefs?.setBool('useSentry', value.toString() == 'true'); + setState(() {}); + }, + ); }