Skip to content

Commit

Permalink
feat(settings): re-add option to disable Sentry logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Sep 1, 2022
1 parent 57bbb80 commit 3d0c520
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 27 deletions.
2 changes: 2 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@
"settings.RestoreFromCloudSuccessMessage": "Your configuration has been restored",
"settings.RestoreFromDevice": "Restore from Device",
"settings.RestoreFromDeviceDescription": "Restore Configuration Data",
"settings.SentryLogging": "Sentry Logging",
"settings.SentryLoggingDescription": "Upload Errors & Crashes to Sentry",
"settings.SignedInFailure": "Failed to Sign In",
"settings.SignedInSuccess": "Successfully Signed In",
"settings.SignedOutFailure": "Failed to Sign Out",
Expand Down
1 change: 1 addition & 0 deletions lib/database/tables/bios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:lunasea/database/table.dart';

enum BIOSDatabase<T> with LunaTableMixin<T> {
DATABASE_CORRUPTION<bool>(false),
SENTRY_LOGGING<bool>(true),
FIRST_BOOT<bool>(true);

@override
Expand Down
6 changes: 0 additions & 6 deletions lib/database/tables/lunasea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enum LunaSeaDatabase<T> with LunaTableMixin<T> {
QUICK_ACTIONS_TAUTULLI<bool>(false),
QUICK_ACTIONS_SEARCH<bool>(false),
USE_24_HOUR_TIME<bool>(false),
DEFAULT_LAUNCH_MODULE<LunaModule>(LunaModule.DASHBOARD),
ENABLE_IN_APP_NOTIFICATIONS<bool>(true),
CHANGELOG_LAST_BUILD_VERSION<int>(0);

Expand Down Expand Up @@ -55,8 +54,6 @@ enum LunaSeaDatabase<T> with LunaTableMixin<T> {
dynamic export() {
LunaSeaDatabase db = this;
switch (db) {
case LunaSeaDatabase.DEFAULT_LAUNCH_MODULE:
return LunaSeaDatabase.DEFAULT_LAUNCH_MODULE.read().key;
case LunaSeaDatabase.DRAWER_MANUAL_ORDER:
return LunaDrawer.moduleOrderedList()
.map<String>((module) => module.key)
Expand All @@ -72,9 +69,6 @@ enum LunaSeaDatabase<T> with LunaTableMixin<T> {
dynamic result;

switch (db) {
case LunaSeaDatabase.DEFAULT_LAUNCH_MODULE:
result = LunaModule.fromKey(value.toString());
break;
case LunaSeaDatabase.DRAWER_MANUAL_ORDER:
List<LunaModule> item = [];
(value as List).cast<String>().forEach((val) {
Expand Down
62 changes: 41 additions & 21 deletions lib/modules/settings/routes/system_logs/route.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
import 'package:lunasea/database/tables/bios.dart';
import 'package:lunasea/modules/settings.dart';
import 'package:lunasea/router/routes/settings.dart';
import 'package:lunasea/system/filesystem/filesystem.dart';
Expand Down Expand Up @@ -44,27 +45,32 @@ class _State extends State<SystemLogsRoute> with LunaScrollControllerMixin {
}

Widget _body() {
return LunaListView(controller: scrollController, children: [
LunaBlock(
title: 'All Logs',
body: const [TextSpan(text: 'View Logs of All Types')],
trailing: const LunaIconButton(icon: Icons.developer_mode_rounded),
onTap: () async => _viewLogs(null),
),
...List.generate(
LunaLogType.values.length,
(index) {
if (LunaLogType.values[index].enabled)
return LunaBlock(
title: LunaLogType.values[index].title,
body: [TextSpan(text: LunaLogType.values[index].description)],
trailing: LunaIconButton(icon: LunaLogType.values[index].icon),
onTap: () async => _viewLogs(LunaLogType.values[index]),
);
return Container(height: 0.0);
},
),
]);
return LunaListView(
controller: scrollController,
children: [
LunaBlock(
title: 'All Logs',
body: const [TextSpan(text: 'View Logs of All Types')],
trailing: const LunaIconButton(icon: Icons.developer_mode_rounded),
onTap: () async => _viewLogs(null),
),
...List.generate(
LunaLogType.values.length,
(index) {
if (LunaLogType.values[index].enabled)
return LunaBlock(
title: LunaLogType.values[index].title,
body: [TextSpan(text: LunaLogType.values[index].description)],
trailing: LunaIconButton(icon: LunaLogType.values[index].icon),
onTap: () async => _viewLogs(LunaLogType.values[index]),
);
return Container(height: 0.0);
},
),
LunaDivider(),
_sentryLogging(),
],
);
}

Future<void> _viewLogs(LunaLogType? type) async {
Expand All @@ -73,6 +79,20 @@ class _State extends State<SystemLogsRoute> with LunaScrollControllerMixin {
});
}

Widget _sentryLogging() {
const db = BIOSDatabase.SENTRY_LOGGING;
return db.watch(
builder: (context, _) => LunaBlock(
title: 'settings.SentryLogging'.tr(),
body: [TextSpan(text: 'settings.SentryLoggingDescription'.tr())],
trailing: LunaSwitch(
value: db.read(),
onChanged: db.update,
),
),
);
}

Widget _clearLogs() {
return LunaButton.text(
text: 'Clear',
Expand Down
2 changes: 2 additions & 0 deletions lib/system/sentry.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:lunasea/database/tables/bios.dart';
import 'package:lunasea/system/environment.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Expand All @@ -11,6 +12,7 @@ class LunaSentry {
}

Future<void> captureException(dynamic error, StackTrace? stackTrace) async {
if (!BIOSDatabase.SENTRY_LOGGING.read()) return;
await Sentry.captureException(error, stackTrace: stackTrace);
}

Expand Down
2 changes: 2 additions & 0 deletions localization/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
"settings.RestoreFromCloudSuccessMessage": "Your configuration has been restored",
"settings.RestoreFromDevice": "Restore from Device",
"settings.RestoreFromDeviceDescription": "Restore Configuration Data",
"settings.SentryLogging": "Sentry Logging",
"settings.SentryLoggingDescription": "Upload Errors & Crashes to Sentry",
"settings.SignedInFailure": "Failed to Sign In",
"settings.SignedInSuccess": "Successfully Signed In",
"settings.SignedOutFailure": "Failed to Sign Out",
Expand Down

0 comments on commit 3d0c520

Please sign in to comment.