diff --git a/assets/i18n/en_US.json b/assets/i18n/en_US.json index 997302a0..c811e82a 100644 --- a/assets/i18n/en_US.json +++ b/assets/i18n/en_US.json @@ -106,6 +106,7 @@ "teamSectionTitle": "Team", "infoSectionTitle": "Info", "advancedSectionTitle": "Advanced", + "privacySectionTitle": "Privacy", "darkThemeLabel": "Dark Mode", "darkThemeHint": "Welcome to the Dark Side", "dynamicThemeLabel": "Material You", @@ -130,7 +131,10 @@ "apiURLHint": "Configure your custom API URL", "selectApiURL": "Select URL", "aboutLabel": "About", - "snackbarMessage": "Copied to clipboard" + "snackbarMessage": "Copied to clipboard", + "sentryLabel": "Sentry Logging", + "sentryHint": "Send anonymous logs to help us improve ReVanced Manager", + "restartAppForChanges": "Restart the app to apply changes" }, "appInfoView": { "widgetTitle": "App Info", diff --git a/lib/main.dart b/lib/main.dart index 7cceb665..d286d0ce 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,19 +20,30 @@ Future main() async { await locator().initialize(); String apiUrl = locator().getApiUrl(); await locator().initialize(apiUrl); + bool isSentryEnabled = locator().isSentryEnabled(); locator().initialize(); await locator().initialize(); tz.initializeTimeZones(); await SentryFlutter.init( (options) { options - ..dsn = Env.SENTRY_DSN + ..dsn = isSentryEnabled ? Env.SENTRY_DSN : '' ..environment = 'alpha' ..release = '0.1' ..tracesSampleRate = 1.0 ..anrEnabled = true ..enableOutOfMemoryTracking = true - ..sampleRate = 1.0; + ..sampleRate = isSentryEnabled ? 1.0 : 0.0 + ..beforeSend = (event, hint) { + print('isSentryEnabled: $isSentryEnabled'); + if (isSentryEnabled) { + print("Sentry event sent"); + return event; + } else { + print("Sentry is disabled"); + return null; + } + } as BeforeSendCallback?; }, appRunner: () => runApp(const MyApp()), ); diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index d12a71e6..c6a79804 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -82,6 +82,15 @@ class ManagerAPI { await _prefs.setBool('useDarkTheme', value); } + bool isSentryEnabled() { + return _prefs.getBool('sentryEnabled') ?? true; + } + + Future setSentryStatus(bool value) async { + await _prefs.setBool('sentryEnabled', value); + print('Sentry status: $value'); + } + List getPatchedApps() { List apps = _prefs.getStringList('patchedApps') ?? []; return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList(); diff --git a/lib/services/toast.dart b/lib/services/toast.dart index 3a47fcf2..cb9a62b7 100644 --- a/lib/services/toast.dart +++ b/lib/services/toast.dart @@ -20,4 +20,15 @@ class Toast { gravity: t.ToastGravity.CENTER, ); } + + void showBottom(String text) { + t.Fluttertoast.showToast( + msg: FlutterI18n.translate( + _fToast.context!, + text, + ), + toastLength: t.Toast.LENGTH_LONG, + gravity: t.ToastGravity.BOTTOM, + ); + } } diff --git a/lib/ui/views/settings/settings_view.dart b/lib/ui/views/settings/settings_view.dart index abbe64f1..2f133f57 100644 --- a/lib/ui/views/settings/settings_view.dart +++ b/lib/ui/views/settings/settings_view.dart @@ -139,6 +139,28 @@ class SettingsView extends StatelessWidget { ], ), _settingsDivider, + SettingsSection( + title: 'settingsView.privacySectionTitle', + children: [ + CustomSwitchTile( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + title: I18nText( + 'settingsView.sentryLabel', + child: const Text( + '', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ), + subtitle: I18nText('settingsView.sentryHint'), + value: model.isSentryEnabled(), + onTap: (value) => model.useSentry(value), + ), + ], + ), + _settingsDivider, SettingsSection( title: 'settingsView.infoSectionTitle', children: [ diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index 8a22036f..c50c8e90 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -10,6 +10,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/services/manager_api.dart'; +import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/settingsView/custom_text_field.dart'; import 'package:share_extend/share_extend.dart'; @@ -23,6 +24,7 @@ const int ANDROID_12_SDK_VERSION = 31; class SettingsViewModel extends BaseViewModel { final NavigationService _navigationService = locator(); final ManagerAPI _managerAPI = locator(); + final Toast _toast = locator(); final TextEditingController _orgPatSourceController = TextEditingController(); final TextEditingController _patSourceController = TextEditingController(); final TextEditingController _orgIntSourceController = TextEditingController(); @@ -313,6 +315,18 @@ class SettingsViewModel extends BaseViewModel { ); } + // disable sentry using switch boolean + + bool isSentryEnabled() { + return _managerAPI.isSentryEnabled(); + } + + void useSentry(bool value) { + _managerAPI.setSentryStatus(value); + _toast.showBottom('settingsView.restartAppForChanges'); + notifyListeners(); + } + Future getSdkVersion() async { AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo; return info.version.sdkInt ?? -1;