From f164140f24b3ac99b951887e5f0ba30d0b66884a Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sat, 16 Sep 2023 15:16:20 +0330 Subject: [PATCH] fix: crashlytics --- lib/bootstrap.dart | 19 ++++++ lib/core/prefs/general_prefs.dart | 17 +++++ lib/firebase_options.dart | 74 -------------------- lib/main_dev.dart | 5 -- lib/main_prod.dart | 4 -- macos/Podfile.lock | 93 ++++++++++++++++++++++++++ macos/Runner.xcodeproj/project.pbxproj | 24 +++++++ 7 files changed, 153 insertions(+), 83 deletions(-) delete mode 100644 lib/firebase_options.dart diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index bd4659b6..f79eb9f7 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'dart:io'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; @@ -43,6 +45,11 @@ Future lazyBootstrap( ], ); + if (container.read(autoCrashReportProvider) && !kDebugMode) { + _loggy.debug("initializing crashlytics"); + await initCrashlytics(); + } + final debug = container.read(debugModeNotifierProvider) || kDebugMode; final filesEditor = container.read(filesEditorServiceProvider); @@ -95,6 +102,18 @@ void initLoggers( ); } +Future initCrashlytics() async { + switch (Platform.operatingSystem) { + case "android" || "ios" || "macos": + await Firebase.initializeApp(); + FlutterError.onError = + FirebaseCrashlytics.instance.recordFlutterFatalError; + default: + _loggy.debug("platform is not supported for crashlytics"); + return; + } +} + Future initAppServices( Result Function(ProviderListenable) read, ) async { diff --git a/lib/core/prefs/general_prefs.dart b/lib/core/prefs/general_prefs.dart index 6af8727b..0b559125 100644 --- a/lib/core/prefs/general_prefs.dart +++ b/lib/core/prefs/general_prefs.dart @@ -21,6 +21,23 @@ class SilentStartNotifier extends _$SilentStartNotifier { } } +@Riverpod(keepAlive: true) +class AutoCrashReport extends _$AutoCrashReport { + late final _pref = Pref( + ref.watch(sharedPreferencesProvider), + "auto_crash_report", + false, + ); + + @override + bool build() => _pref.getValue(); + + Future update(bool value) { + state = value; + return _pref.update(value); + } +} + @Riverpod(keepAlive: true) class DebugModeNotifier extends _$DebugModeNotifier { late final _pref = Pref( diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart deleted file mode 100644 index ca9fb158..00000000 --- a/lib/firebase_options.dart +++ /dev/null @@ -1,74 +0,0 @@ -// File generated by FlutterFire CLI. -// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members -import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; -import 'package:flutter/foundation.dart' - show defaultTargetPlatform, kIsWeb, TargetPlatform; - -/// Default [FirebaseOptions] for use with your Firebase apps. -/// -/// Example: -/// ```dart -/// import 'firebase_options.dart'; -/// // ... -/// await Firebase.initializeApp( -/// options: DefaultFirebaseOptions.currentPlatform, -/// ); -/// ``` -class DefaultFirebaseOptions { - static FirebaseOptions get currentPlatform { - if (kIsWeb) { - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for web - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - } - switch (defaultTargetPlatform) { - case TargetPlatform.android: - return android; - case TargetPlatform.iOS: - return ios; - case TargetPlatform.macOS: - return macos; - case TargetPlatform.windows: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for windows - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - case TargetPlatform.linux: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for linux - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - default: - throw UnsupportedError( - 'DefaultFirebaseOptions are not supported for this platform.', - ); - } - } - - static const FirebaseOptions android = FirebaseOptions( - apiKey: 'AIzaSyDhiPAfkcUkQKcNXCUUcKL51K5UqRd7WXA', - appId: '1:372003342382:android:c33c6eb99da7ceb76fb7bf', - messagingSenderId: '372003342382', - projectId: 'hiddify-flutter', - storageBucket: 'hiddify-flutter.appspot.com', - ); - - static const FirebaseOptions ios = FirebaseOptions( - apiKey: 'AIzaSyDs7pee9vjdKfUYFbJvHo8rDwqp36dkPRI', - appId: '1:372003342382:ios:a579c1abfc54046a6fb7bf', - messagingSenderId: '372003342382', - projectId: 'hiddify-flutter', - storageBucket: 'hiddify-flutter.appspot.com', - iosBundleId: 'com.hiddify.hiddify', - ); - - static const FirebaseOptions macos = FirebaseOptions( - apiKey: 'AIzaSyDs7pee9vjdKfUYFbJvHo8rDwqp36dkPRI', - appId: '1:372003342382:ios:dd40035472392b346fb7bf', - messagingSenderId: '372003342382', - projectId: 'hiddify-flutter', - storageBucket: 'hiddify-flutter.appspot.com', - iosBundleId: 'com.hiddify.hiddify.RunnerTests', - ); -} diff --git a/lib/main_dev.dart b/lib/main_dev.dart index b795ca4c..8dcdbd01 100644 --- a/lib/main_dev.dart +++ b/lib/main_dev.dart @@ -1,13 +1,8 @@ -import 'package:firebase_core/firebase_core.dart'; -import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/widgets.dart'; import 'package:hiddify/bootstrap.dart'; import 'package:hiddify/domain/environment.dart'; void main() async { final widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp(); - FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; - return lazyBootstrap(widgetsBinding, Environment.dev); } diff --git a/lib/main_prod.dart b/lib/main_prod.dart index 1f7c2673..81b713ca 100644 --- a/lib/main_prod.dart +++ b/lib/main_prod.dart @@ -1,12 +1,8 @@ -import 'package:firebase_core/firebase_core.dart'; -import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/widgets.dart'; import 'package:hiddify/bootstrap.dart'; import 'package:hiddify/domain/environment.dart'; void main() async { final widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp(); - FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; return lazyBootstrap(widgetsBinding, Environment.prod); } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 7dffbc33..7433b5cc 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -1,14 +1,75 @@ PODS: + - Firebase/CoreOnly (10.12.0): + - FirebaseCore (= 10.12.0) + - Firebase/Crashlytics (10.12.0): + - Firebase/CoreOnly + - FirebaseCrashlytics (~> 10.12.0) + - firebase_core (2.15.1): + - Firebase/CoreOnly (~> 10.12.0) + - FlutterMacOS + - firebase_crashlytics (3.3.5): + - Firebase/CoreOnly (~> 10.12.0) + - Firebase/Crashlytics (~> 10.12.0) + - firebase_core + - FlutterMacOS + - FirebaseCore (10.12.0): + - FirebaseCoreInternal (~> 10.0) + - GoogleUtilities/Environment (~> 7.8) + - GoogleUtilities/Logger (~> 7.8) + - FirebaseCoreExtension (10.15.0): + - FirebaseCore (~> 10.0) + - FirebaseCoreInternal (10.15.0): + - "GoogleUtilities/NSData+zlib (~> 7.8)" + - FirebaseCrashlytics (10.12.0): + - FirebaseCore (~> 10.5) + - FirebaseInstallations (~> 10.0) + - FirebaseSessions (~> 10.5) + - GoogleDataTransport (~> 9.2) + - GoogleUtilities/Environment (~> 7.8) + - nanopb (< 2.30910.0, >= 2.30908.0) + - PromisesObjC (~> 2.1) + - FirebaseInstallations (10.15.0): + - FirebaseCore (~> 10.0) + - GoogleUtilities/Environment (~> 7.8) + - GoogleUtilities/UserDefaults (~> 7.8) + - PromisesObjC (~> 2.1) + - FirebaseSessions (10.15.0): + - FirebaseCore (~> 10.5) + - FirebaseCoreExtension (~> 10.0) + - FirebaseInstallations (~> 10.0) + - GoogleDataTransport (~> 9.2) + - GoogleUtilities/Environment (~> 7.10) + - nanopb (< 2.30910.0, >= 2.30908.0) + - PromisesSwift (~> 2.1) - flutter_local_notifications (0.0.1): - FlutterMacOS - FlutterMacOS (1.0.0) + - GoogleDataTransport (9.2.5): + - GoogleUtilities/Environment (~> 7.7) + - nanopb (< 2.30910.0, >= 2.30908.0) + - PromisesObjC (< 3.0, >= 1.2) + - GoogleUtilities/Environment (7.11.5): + - PromisesObjC (< 3.0, >= 1.2) + - GoogleUtilities/Logger (7.11.5): + - GoogleUtilities/Environment + - "GoogleUtilities/NSData+zlib (7.11.5)" + - GoogleUtilities/UserDefaults (7.11.5): + - GoogleUtilities/Logger - mobile_scanner (3.0.0): - FlutterMacOS + - nanopb (2.30909.0): + - nanopb/decode (= 2.30909.0) + - nanopb/encode (= 2.30909.0) + - nanopb/decode (2.30909.0) + - nanopb/encode (2.30909.0) - package_info_plus (0.0.1): - FlutterMacOS - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS + - PromisesObjC (2.3.1) + - PromisesSwift (2.3.1): + - PromisesObjC (= 2.3.1) - protocol_handler (0.0.1): - FlutterMacOS - screen_retriever (0.0.1): @@ -41,6 +102,8 @@ PODS: - FlutterMacOS DEPENDENCIES: + - firebase_core (from `Flutter/ephemeral/.symlinks/plugins/firebase_core/macos`) + - firebase_crashlytics (from `Flutter/ephemeral/.symlinks/plugins/firebase_crashlytics/macos`) - flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`) - FlutterMacOS (from `Flutter/ephemeral`) - mobile_scanner (from `Flutter/ephemeral/.symlinks/plugins/mobile_scanner/macos`) @@ -57,9 +120,25 @@ DEPENDENCIES: SPEC REPOS: trunk: + - Firebase + - FirebaseCore + - FirebaseCoreExtension + - FirebaseCoreInternal + - FirebaseCrashlytics + - FirebaseInstallations + - FirebaseSessions + - GoogleDataTransport + - GoogleUtilities + - nanopb + - PromisesObjC + - PromisesSwift - sqlite3 EXTERNAL SOURCES: + firebase_core: + :path: Flutter/ephemeral/.symlinks/plugins/firebase_core/macos + firebase_crashlytics: + :path: Flutter/ephemeral/.symlinks/plugins/firebase_crashlytics/macos flutter_local_notifications: :path: Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos FlutterMacOS: @@ -88,11 +167,25 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos SPEC CHECKSUMS: + Firebase: 07150e75d142fb9399f6777fa56a187b17f833a0 + firebase_core: 559d892df9267acc6b7254d46fb3041866777509 + firebase_crashlytics: 5c146808f99644445d69c3dc2eb20324717edd00 + FirebaseCore: f86a1394906b97ac445ae49c92552a9425831bed + FirebaseCoreExtension: d3f1ea3725fb41f56e8fbfb29eeaff54e7ffb8f6 + FirebaseCoreInternal: 2f4bee5ed00301b5e56da0849268797a2dd31fb4 + FirebaseCrashlytics: c4d111b7430c49744c74bcc6346ea00868661ac8 + FirebaseInstallations: cae95cab0f965ce05b805189de1d4c70b11c76fb + FirebaseSessions: ee59a7811bef4c15f65ef6472f3210faa293f9c8 flutter_local_notifications: 3805ca215b2fb7f397d78b66db91f6a747af52e4 FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 + GoogleDataTransport: 54dee9d48d14580407f8f5fbf2f496e92437a2f2 + GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084 mobile_scanner: ed7618fb749adc6574563e053f3b8e5002c13994 + nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 + PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4 + PromisesSwift: 28dca69a9c40779916ac2d6985a0192a5cb4a265 protocol_handler: 587e1caf6c0b92ce351ab14081968dae49cb8cc6 screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38 share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7 diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 870e835b..16e84127 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -244,6 +244,7 @@ 33CC110E2044A8840003C045 /* Bundle Framework */, 3399D490228B24CF009A79C7 /* ShellScript */, DDB714AFDEF721265C0C3AF7 /* [CP] Embed Pods Frameworks */, + D252A7A96F637452F3C3E2BE /* [firebase_crashlytics] Crashlytics Upload Symbols */, ); buildRules = ( ); @@ -407,6 +408,29 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + D252A7A96F637452F3C3E2BE /* [firebase_crashlytics] Crashlytics Upload Symbols */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}\"", + "\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/\"", + "\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist\"", + "\"$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)\"", + "\"$(PROJECT_DIR)/firebase_app_id_file.json\"", + ); + name = "[firebase_crashlytics] Crashlytics Upload Symbols"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$PODS_ROOT/FirebaseCrashlytics/upload-symbols\" --flutter-project \"$PROJECT_DIR/firebase_app_id_file.json\" "; + }; DDB714AFDEF721265C0C3AF7 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647;