TF-4136 Fix duplicate Executor instance creation.

This commit is contained in:
dab246
2026-01-12 10:56:30 +07:00
committed by Dat H. Pham
parent 944029d16c
commit b6f7f7d846
15 changed files with 69 additions and 27 deletions
+1
View File
@@ -62,6 +62,7 @@ export 'utils/html/html_utils.dart';
export 'utils/web_link_generator.dart';
export 'utils/sentry/sentry_manager.dart';
export 'utils/config/env_loader.dart';
export 'utils/sentry/sentry_dio_helper.dart';
// Views
export 'presentation/views/text/slogan_builder.dart';
+1
View File
@@ -30,6 +30,7 @@ class ApplicationManager {
_versionCache = null;
_cachedWebUserAgent = null;
_cachedMobileUserAgent = null;
_isMobileUserAgentInitialized = false;
}
Future<PackageInfo> getPackageInfo() async {
+1
View File
@@ -29,6 +29,7 @@ class EnvLoader {
);
} catch (e) {
logWarning('EnvLoader::loadFcmConfigFileToEnv: Exception = $e');
// FCM config is optional; reload base config to restore dotenv.env state
await onCallBack?.call();
}
}
+5 -7
View File
@@ -45,7 +45,7 @@ class SentryConfig {
});
/// Load configuration from an env file.
static Future<SentryConfig> load() async {
static Future<SentryConfig?> load() async {
await EnvLoader.loadConfigFromEnv();
final sentryAvailable = dotenv.get('SENTRY_ENABLED', fallback: 'false');
@@ -54,12 +54,10 @@ class SentryConfig {
final sentryDSN = dotenv.get('SENTRY_DSN', fallback: '');
final sentryEnvironment = dotenv.get('SENTRY_ENVIRONMENT', fallback: '');
if (!isAvailable) {
throw Exception('Sentry is not available');
}
if (sentryDSN.trim().isEmpty || sentryEnvironment.trim().isEmpty) {
throw Exception('Sentry configuration is missing');
if (!isAvailable ||
sentryDSN.trim().isEmpty ||
sentryEnvironment.trim().isEmpty) {
return null;
}
final appVersion = await ApplicationManager().getAppVersion();
@@ -0,0 +1,15 @@
import 'package:core/utils/sentry/sentry_manager.dart';
import 'package:dio/dio.dart';
import 'package:sentry_dio/sentry_dio.dart';
class SentryDioHelper {
static void addIfAvailable(Dio dio) {
if (!SentryManager.instance.isSentryAvailable) return;
final alreadyHasSentry = dio.interceptors.any(
(i) => i.runtimeType.toString().contains('FailedRequestInterceptor'));
if (!alreadyHasSentry) {
dio.addSentry();
}
}
}
@@ -11,14 +11,19 @@ class SentryInitializer {
'x-auth',
'x-token',
'api-key',
'x-api-key',
'apikey',
'secret',
'bearer',
'session',
'password',
];
static Future<bool> init(FutureOr<void> Function() appRunner) async {
final config = await SentryConfig.load();
if (config == null) return false;
await SentryFlutter.init(
(options) {
options.dsn = config.dsn;
@@ -22,6 +22,7 @@ class SentryManager {
try {
if (_isSentryAvailable) {
log('[SentryManager] Already initialized, skipping');
await appRunner();
return;
}
_isSentryAvailable = await SentryInitializer.init(appRunner);
+8
View File
@@ -1009,6 +1009,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "9.8.0"
sentry_dio:
dependency: "direct main"
description:
name: sentry_dio
sha256: bee438fd790c534da77f0a6c9cd04c54c818184b8a54bbe7d916489c8aad56a0
url: "https://pub.dev"
source: hosted
version: "9.8.0"
sentry_flutter:
dependency: "direct main"
description:
+2
View File
@@ -105,6 +105,8 @@ dependencies:
sentry_flutter: 9.8.0
sentry_dio: 9.8.0
dev_dependencies:
flutter_test:
sdk: flutter