From 7e3e5f19ff00fc5c9abafdcf4d999e46c671f5d6 Mon Sep 17 00:00:00 2001 From: Badr Kouki Date: Mon, 18 Nov 2024 10:56:37 +0100 Subject: [PATCH] refactor: update bugsee manager state variables --- .../lib/business/bugsee/bugsee_manager.dart | 64 +++++++++++-------- .../bugsee_configuration_widget.dart | 16 ++--- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/app/lib/business/bugsee/bugsee_manager.dart b/src/app/lib/business/bugsee/bugsee_manager.dart index c7c89741..654e48e1 100644 --- a/src/app/lib/business/bugsee/bugsee_manager.dart +++ b/src/app/lib/business/bugsee/bugsee_manager.dart @@ -18,11 +18,25 @@ abstract interface class BugseeManager { required BugseeRepository bugseeRepository, }) = _BugseeManager; - bool get isRequireRestart; - - bool get bugseeIsEnabled; - bool get captureVideoIsEnabled; - bool get isValidConfiguration; + /// indicate if the app require a restart to reactivate the bugsee configurations + /// + /// `true` only if `isConfigurationValid == true` and bugsee is turned on + bool get isRestartRequired; + + /// indicate if bugsee is enabled or not + /// by default bugsee is enabled if `isConfigurationValid == true`. + bool get isBugseeEnabled; + + /// indicate whether video capturing is enabled or not. + /// enabled by default if `isBugseeEnabled == true`. + /// + /// cannot be true if `isBugseeEnabled == false`. + bool get isVideoCaptureEnabled; + + /// indicate if bugsee configuration is valid + /// config is valid if app in release mode and the provided token is valid + /// following the [bugseeTokenFormat] regex. + bool get isConfigurationValid; /// initialize bugsee with given token /// bugsee is not available in debug mode @@ -66,16 +80,16 @@ final class _BugseeManager implements BugseeManager { }); @override - bool isRequireRestart = false; + bool isRestartRequired = false; @override - bool bugseeIsEnabled = false; + bool isBugseeEnabled = false; @override - late bool captureVideoIsEnabled = false; + late bool isVideoCaptureEnabled = false; @override - bool isValidConfiguration = true; + bool isConfigurationValid = true; late bool _isBugSeeInitialized; BugseeLaunchOptions? launchOptions; @@ -91,14 +105,14 @@ final class _BugseeManager implements BugseeManager { _isBugSeeInitialized = false; if (kDebugMode) { - isValidConfiguration = false; + isConfigurationValid = false; logger.i("BUGSEE: deactivated in debug mode"); return; } if (bugseeToken == null || !RegExp(bugseeTokenFormat).hasMatch(bugseeToken)) { - isValidConfiguration = false; + isConfigurationValid = false; logger.i( "BUGSEE: token is null or invalid, bugsee won't be initialized", ); @@ -109,8 +123,8 @@ final class _BugseeManager implements BugseeManager { await launchBugseeLogger(bugseeToken); } - bugseeIsEnabled = _isBugSeeInitialized; - captureVideoIsEnabled = _isBugSeeInitialized && + isBugseeEnabled = _isBugSeeInitialized; + isVideoCaptureEnabled = _isBugSeeInitialized && (bugseeConfigurationData.isVideoCaptureEnabled ?? true); } @@ -144,7 +158,7 @@ final class _BugseeManager implements BugseeManager { required Exception exception, StackTrace? stackTrace, }) async { - if (bugseeIsEnabled) { + if (isBugseeEnabled) { await Bugsee.logException(exception, stackTrace); } } @@ -154,30 +168,30 @@ final class _BugseeManager implements BugseeManager { required Exception exception, StackTrace? stackTrace, }) async { - if (bugseeIsEnabled) { + if (isBugseeEnabled) { await Bugsee.logUnhandledException(exception); } } @override - Future setIsBugseeEnabled(bool isBugseeEnabled) async { - if (isValidConfiguration) { + Future setIsBugseeEnabled(bool value) async { + if (isConfigurationValid) { + isBugseeEnabled = value; await bugseeRepository.setIsBugseeEnabled(isBugseeEnabled); - isRequireRestart = _isBugSeeInitialized && isBugseeEnabled; - bugseeIsEnabled = isBugseeEnabled; - captureVideoIsEnabled = bugseeIsEnabled; + isRestartRequired = _isBugSeeInitialized && isBugseeEnabled; + isVideoCaptureEnabled = isBugseeEnabled; - if (!isRequireRestart) { + if (!isRestartRequired) { await Bugsee.stop(); } } } @override - Future setIsVideoCaptureEnabled(bool isVideoCaptureEnabled) async { - if (bugseeIsEnabled) { - captureVideoIsEnabled = isVideoCaptureEnabled; + Future setIsVideoCaptureEnabled(bool value) async { + if (isBugseeEnabled) { + isVideoCaptureEnabled = value; await bugseeRepository.setIsVideoCaptureEnabled(isVideoCaptureEnabled); if (!isVideoCaptureEnabled) { await Bugsee.pause(); @@ -189,7 +203,7 @@ final class _BugseeManager implements BugseeManager { @override Future showCaptureLogReport() async { - if (bugseeIsEnabled) { + if (isBugseeEnabled) { await Bugsee.showReportDialog(); } } diff --git a/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart b/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart index 5f53fc4d..3952cbf5 100644 --- a/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart +++ b/src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart @@ -23,9 +23,9 @@ class _BugseeConfigurationWidgetState extends State { @override void initState() { super.initState(); - isConfigEnabled = bugseeManager.bugseeIsEnabled; - isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled; - requireRestart = bugseeManager.isRequireRestart; + isConfigEnabled = bugseeManager.isBugseeEnabled; + isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled; + requireRestart = bugseeManager.isRestartRequired; } @override @@ -34,7 +34,7 @@ class _BugseeConfigurationWidgetState extends State { children: [ Column( children: [ - if (!bugseeManager.isValidConfiguration) + if (!bugseeManager.isConfigurationValid) Container( color: const Color.fromARGB(170, 255, 0, 0), child: const Text( @@ -68,9 +68,9 @@ class _BugseeConfigurationWidgetState extends State { onChanged: (value) async { await bugseeManager.setIsBugseeEnabled(value); setState(() { - isConfigEnabled = bugseeManager.bugseeIsEnabled; - isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled; - requireRestart = bugseeManager.isRequireRestart; + isConfigEnabled = bugseeManager.isBugseeEnabled; + isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled; + requireRestart = bugseeManager.isRestartRequired; }); }, ), @@ -80,7 +80,7 @@ class _BugseeConfigurationWidgetState extends State { onChanged: (value) async { await bugseeManager.setIsVideoCaptureEnabled(value); setState(() { - isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled; + isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled; }); }, ),