diff --git a/src/app/lib/business/bugsee/bugsee_config_state.dart b/src/app/lib/business/bugsee/bugsee_config_state.dart index 1ede838a..8276b309 100644 --- a/src/app/lib/business/bugsee/bugsee_config_state.dart +++ b/src/app/lib/business/bugsee/bugsee_config_state.dart @@ -1,5 +1,16 @@ import 'package:equatable/equatable.dart'; +enum ConfigErrorEnum { + invalidReleaseMode(error: 'Bugsee is disabled in debug mode'), + invalidToken(error: 'Invalid token, cannot start Bugsee reporting'), + invalidPlatform(error: 'Bugsee cannot be configured on this platform'); + + final String error; + const ConfigErrorEnum({ + required this.error, + }); +} + final class BugseeConfigState extends Equatable { /// Indicate if the app require a restart to reactivate the bugsee configurations /// @@ -45,6 +56,9 @@ final class BugseeConfigState extends Equatable { /// By default it's enabled. final bool attachLogFile; + /// Indicate the configuration error type (debug, invalid token or invalid platform) + final ConfigErrorEnum? configErrorEnum; + const BugseeConfigState({ this.isRestartRequired = false, this.isBugseeEnabled = false, @@ -54,6 +68,7 @@ final class BugseeConfigState extends Equatable { this.isLogCollectionEnabled = false, this.isLogFilterEnabled = false, this.attachLogFile = false, + this.configErrorEnum, }); BugseeConfigState copyWith({ @@ -65,6 +80,7 @@ final class BugseeConfigState extends Equatable { bool? isLogCollectionEnabled, bool? isLogFilterEnabled, bool? attachLogFile, + ConfigErrorEnum? configErrorEnum, }) => BugseeConfigState( isRestartRequired: isRestartRequired ?? this.isRestartRequired, @@ -77,6 +93,7 @@ final class BugseeConfigState extends Equatable { isLogCollectionEnabled ?? this.isLogCollectionEnabled, isVideoCaptureEnabled: isVideoCaptureEnabled ?? this.isVideoCaptureEnabled, + configErrorEnum: configErrorEnum ?? this.configErrorEnum, ); @override diff --git a/src/app/lib/business/bugsee/bugsee_manager.dart b/src/app/lib/business/bugsee/bugsee_manager.dart index e9cd9e96..7748f18f 100644 --- a/src/app/lib/business/bugsee/bugsee_manager.dart +++ b/src/app/lib/business/bugsee/bugsee_manager.dart @@ -128,6 +128,15 @@ final class _BugseeManager implements BugseeManager { this.loggerManager = loggerManager; this.bugseeRepository = bugseeRepository; + if (!Platform.isIOS && !Platform.isAndroid) { + _currentState = _currentState.copyWith( + isConfigurationValid: false, + configErrorEnum: ConfigErrorEnum.invalidPlatform, + ); + logger.i("BUGSEE: ${_currentState.configErrorEnum?.error}"); + return; + } + configurationData = await bugseeRepository.getBugseeConfiguration(); configurationData = configurationData.copyWith( isLogCollectionEnabled: configurationData.isLogCollectionEnabled ?? @@ -155,8 +164,9 @@ final class _BugseeManager implements BugseeManager { if (kDebugMode) { _currentState = _currentState.copyWith( isConfigurationValid: false, + configErrorEnum: ConfigErrorEnum.invalidReleaseMode, ); - logger.i("BUGSEE: deactivated in debug mode"); + logger.i("BUGSEE: ${_currentState.configErrorEnum?.error}"); return; } @@ -164,9 +174,10 @@ final class _BugseeManager implements BugseeManager { !RegExp(bugseeTokenFormat).hasMatch(bugseeToken)) { _currentState = _currentState.copyWith( isConfigurationValid: false, + configErrorEnum: ConfigErrorEnum.invalidToken, ); logger.i( - "BUGSEE: token is null or invalid, bugsee won't be initialized", + "BUGSEE: ${_currentState.configErrorEnum?.error}", ); return; } diff --git a/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart b/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart index 50096310..7d048bb1 100644 --- a/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart +++ b/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart @@ -4,7 +4,6 @@ import 'package:app/business/bugsee/bugsee_config_state.dart'; import 'package:app/business/bugsee/bugsee_manager.dart'; import 'package:app/presentation/diagnostic/diagnostic_button.dart'; import 'package:app/presentation/diagnostic/diagnostic_switch.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; @@ -33,14 +32,12 @@ class _BugseeConfigurationWidgetState extends State { children: [ Column( children: [ - if (!bugseeManager.bugseeConfigState.isConfigurationValid) + if (!state.isConfigurationValid) Container( color: const Color.fromARGB(170, 255, 0, 0), - child: const Text( - kDebugMode - ? "Bugsee is disabled in debug mode." - : "Invalid Bugsee token, capturing exceptions could not start", - style: TextStyle( + child: Text( + state.configErrorEnum?.error ?? '', + style: const TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold,