From f31a60d9bb72d59c043adb76c272eb5c9816324b Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Sat, 15 Oct 2022 18:29:50 +0530 Subject: [PATCH] feat: make firebase crashlytics optional. --- assets/i18n/en_US.json | 4 +++- lib/main.dart | 22 ++++++++++++++----- lib/services/manager_api.dart | 9 ++++++++ lib/ui/views/settings/settings_view.dart | 20 ++++++++++++++++- lib/ui/views/settings/settings_viewmodel.dart | 10 +++++++++ 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/assets/i18n/en_US.json b/assets/i18n/en_US.json index c811e82a..3666ecc4 100644 --- a/assets/i18n/en_US.json +++ b/assets/i18n/en_US.json @@ -106,7 +106,7 @@ "teamSectionTitle": "Team", "infoSectionTitle": "Info", "advancedSectionTitle": "Advanced", - "privacySectionTitle": "Privacy", + "logsSectionTitle": "Logs", "darkThemeLabel": "Dark Mode", "darkThemeHint": "Welcome to the Dark Side", "dynamicThemeLabel": "Material You", @@ -134,6 +134,8 @@ "snackbarMessage": "Copied to clipboard", "sentryLabel": "Sentry Logging", "sentryHint": "Send anonymous logs to help us improve ReVanced Manager", + "firebaseCrashlyticsLabel": "Firebase Crashlytics", + "firebaseCrashlyticsHint": "Send anonymous crash reports to help us improve ReVanced Manager", "restartAppForChanges": "Restart the app to apply changes" }, "appInfoView": { diff --git a/lib/main.dart b/lib/main.dart index d4a0b34d..1a818d9d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,12 +23,24 @@ Future main() async { await locator().initialize(); String apiUrl = locator().getApiUrl(); await locator().initialize(apiUrl); - // Remove this line if you are building from source and don't have firebase - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); bool isSentryEnabled = locator().isSentryEnabled(); + bool isCrashlyticsEnabled = locator().isCrashlyticsEnabled(); + // Remove this line if you are building from source and don't have firebase config + if (isCrashlyticsEnabled) { + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + Firebase.app().setAutomaticDataCollectionEnabled(true); + } + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + Firebase.app().setAutomaticDataCollectionEnabled(false); locator().initialize(); await locator().initialize(); tz.initializeTimeZones(); + + // Remove this line if you are building from source and don't have sentry configured await SentryFlutter.init( (options) { options @@ -52,9 +64,9 @@ Future main() async { }, appRunner: () { // Pass all uncaught errors from the framework to Crashlytics. - FlutterError.onError = - FirebaseCrashlytics.instance.recordFlutterFatalError; - + if (isCrashlyticsEnabled) { + FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; + } runApp(const MyApp()); }, ); diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index c6a79804..4eecfcc9 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -91,6 +91,15 @@ class ManagerAPI { print('Sentry status: $value'); } + bool isCrashlyticsEnabled() { + return _prefs.getBool('crashlyticsEnabled') ?? true; + } + + Future setCrashlyticsStatus(bool value) async { + await _prefs.setBool('crashlyticsEnabled', value); + print('Crashlytics status: $value'); + } + List getPatchedApps() { List apps = _prefs.getStringList('patchedApps') ?? []; return apps.map((a) => PatchedApplication.fromJson(jsonDecode(a))).toList(); diff --git a/lib/ui/views/settings/settings_view.dart b/lib/ui/views/settings/settings_view.dart index 2f133f57..c0933e3b 100644 --- a/lib/ui/views/settings/settings_view.dart +++ b/lib/ui/views/settings/settings_view.dart @@ -140,7 +140,7 @@ class SettingsView extends StatelessWidget { ), _settingsDivider, SettingsSection( - title: 'settingsView.privacySectionTitle', + title: 'settingsView.logsSectionTitle', children: [ CustomSwitchTile( padding: const EdgeInsets.symmetric(horizontal: 20.0), @@ -158,6 +158,24 @@ class SettingsView extends StatelessWidget { value: model.isSentryEnabled(), onTap: (value) => model.useSentry(value), ), + const SizedBox(height: 20.0), + CustomSwitchTile( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + title: I18nText( + 'settingsView.firebaseCrashlyticsLabel', + child: const Text( + '', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ), + subtitle: + I18nText('settingsView.firebaseCrashlyticsHint'), + value: model.isCrashlyticsEnabled(), + onTap: (value) => model.useCrashlytics(value), + ), ], ), _settingsDivider, diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index c50c8e90..347e468d 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -327,6 +327,16 @@ class SettingsViewModel extends BaseViewModel { notifyListeners(); } + bool isCrashlyticsEnabled() { + return _managerAPI.isCrashlyticsEnabled(); + } + + void useCrashlytics(bool value) { + _managerAPI.setCrashlyticsStatus(value); + _toast.showBottom('settingsView.restartAppForChanges'); + notifyListeners(); + } + Future getSdkVersion() async { AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo; return info.version.sdkInt ?? -1;