Skip to content

Commit

Permalink
Add sentry to setting and initial popup to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Kara-Zor-El committed Feb 14, 2024
1 parent f0b1220 commit b2cd75a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
50 changes: 49 additions & 1 deletion lib/screens/MainScreens/mainMenu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _MainMenuState extends State<MainMenu> {
}

bool force = false;
SharedPreferences? prefs;

Future<void> _fetchPage(int pageKey) async {
logger.i('pageKey: $pageKey');
Expand All @@ -91,13 +92,17 @@ class _MainMenuState extends State<MainMenu> {
}
}

Future<void> getSharedPrefs() async {
prefs = await SharedPreferences.getInstance();
}

@override
void initState() {
_pagingController.addPageRequestListener((pageKey) {
_fetchPage(pageKey);
});
super.initState();
// fetchCategories();
getSharedPrefs().then((value) => setUseSentry());
}

// dispose
Expand All @@ -106,6 +111,49 @@ class _MainMenuState extends State<MainMenu> {
super.dispose();
}

bool useSentryNull() {
return prefs?.getBool("useSentry") == null;
}

Future<void> 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) {
Expand Down
27 changes: 27 additions & 0 deletions lib/screens/MainScreens/settingsScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
const SizedBox(
height: 20,
),
FutureBuilder(
future: useSentrySettings(),
builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
return snapshot.data ?? Container();
},
),
const SizedBox(
height: 20,
),
// experimentalFeaturesSettings(),
// button to show log file
// logToFile(),
Expand Down Expand Up @@ -720,4 +729,22 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
},
);

// useSentry settings
Future<Widget> 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: <String, String>{
'true': AppLocalizations.of(context)?.yes ?? 'Yes',
'false': AppLocalizations.of(context)?.no ?? 'No',
},
onChange: (value) async {
debugPrint(value);
prefs?.setBool('useSentry', value.toString() == 'true');
setState(() {});
},
);
}

0 comments on commit b2cd75a

Please sign in to comment.