From f1ae924724c3019bd844dbb86b7f2dd0d0f09be5 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Tue, 21 Mar 2023 15:02:43 +0800 Subject: [PATCH] fix: `countly` double init due to rebuild app --- ios/Runner.xcodeproj/project.pbxproj | 12 ++++++------ lib/core/analysis.dart | 8 ++++---- lib/data/res/build_data.dart | 9 ++++----- lib/main.dart | 27 ++++++++++++++------------- lib/view/page/home.dart | 4 +++- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 7cbdcf03..6b4283ae 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -359,7 +359,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 239; + CURRENT_PROJECT_VERSION = 241; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -367,7 +367,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.239; + MARKETING_VERSION = 1.0.241; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -490,7 +490,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 239; + CURRENT_PROJECT_VERSION = 241; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -498,7 +498,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.239; + MARKETING_VERSION = 1.0.241; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -515,7 +515,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 239; + CURRENT_PROJECT_VERSION = 241; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -523,7 +523,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.239; + MARKETING_VERSION = 1.0.241; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/lib/core/analysis.dart b/lib/core/analysis.dart index 5778a151..86224a69 100644 --- a/lib/core/analysis.dart +++ b/lib/core/analysis.dart @@ -12,14 +12,14 @@ class Analysis { static const _url = 'https://countly.xuty.cc'; static const _key = '80372a2a66424b32d0ac8991bfa1ef058bd36b1f'; - static bool _enabled = false; + static bool enabled = false; static Future init() async { if (!BuildMode.isRelease) { return; } if (isAndroid || isIOS) { - _enabled = true; + enabled = true; final config = CountlyConfig(_url, _key) .setLoggingEnabled(false) .enableCrashReporting(); @@ -33,13 +33,13 @@ class Analysis { } static void recordView(String view) { - if (_enabled) { + if (enabled) { Countly.recordView(view); } } static void recordException(Object exception, [bool fatal = false]) { - if (_enabled) { + if (enabled) { Countly.logException(exception.toString(), !fatal, null); } } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index b122941a..e5f1161b 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,9 +2,8 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 239; - static const String engine = - "Flutter 3.7.7 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 2ad6cd72c0 (13 days ago) • 2023-03-08 09:41:59 -0800\nEngine • revision 1837b5be5f\nTools • Dart 2.19.4 • DevTools 2.20.1\n"; - static const String buildAt = "2023-03-21 14:03:13.656226"; - static const int modifications = 17; + static const int build = 241; + static const String engine = "Flutter 3.7.7 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 2ad6cd72c0 (13 days ago) • 2023-03-08 09:41:59 -0800\nEngine • revision 1837b5be5f\nTools • Dart 2.19.4 • DevTools 2.20.1\n"; + static const String buildAt = "2023-03-21 15:00:34.919375"; + static const int modifications = 6; } diff --git a/lib/main.dart b/lib/main.dart index c8b7f49d..cec90226 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -82,19 +82,20 @@ Future main() async { runInZone(() async { await initApp(); runApp( - MultiProvider( - providers: [ - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ChangeNotifierProvider(create: (_) => locator()), - ], - child: RebuildWidget( + RebuildWidget( + child: MultiProvider( + providers: [ + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ChangeNotifierProvider( + create: (_) => locator()), + ChangeNotifierProvider(create: (_) => locator()), + ], child: MyApp(), ), ), diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 061354cb..74174be4 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -308,6 +308,8 @@ class _MyHomePageState extends State await GetIt.I.allReady(); await locator().loadLocalData(); await doUpdate(context); - await Analysis.init(); + if (!Analysis.enabled) { + await Analysis.init(); + } } }