Skip to content

Commit

Permalink
chore: add platform check when intializing Bugsee
Browse files Browse the repository at this point in the history
  • Loading branch information
koukibadr committed Nov 22, 2024
1 parent f6a6938 commit 9906020
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
17 changes: 17 additions & 0 deletions src/app/lib/business/bugsee/bugsee_config_state.dart
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down Expand Up @@ -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,
Expand All @@ -54,6 +68,7 @@ final class BugseeConfigState extends Equatable {
this.isLogCollectionEnabled = false,
this.isLogFilterEnabled = false,
this.attachLogFile = false,
this.configErrorEnum,
});

BugseeConfigState copyWith({
Expand All @@ -65,6 +80,7 @@ final class BugseeConfigState extends Equatable {
bool? isLogCollectionEnabled,
bool? isLogFilterEnabled,
bool? attachLogFile,
ConfigErrorEnum? configErrorEnum,
}) =>
BugseeConfigState(
isRestartRequired: isRestartRequired ?? this.isRestartRequired,
Expand All @@ -77,6 +93,7 @@ final class BugseeConfigState extends Equatable {
isLogCollectionEnabled ?? this.isLogCollectionEnabled,
isVideoCaptureEnabled:
isVideoCaptureEnabled ?? this.isVideoCaptureEnabled,
configErrorEnum: configErrorEnum ?? this.configErrorEnum,
);

@override
Expand Down
15 changes: 13 additions & 2 deletions src/app/lib/business/bugsee/bugsee_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ??
Expand Down Expand Up @@ -155,18 +164,20 @@ 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;
}

if (bugseeToken == null ||
!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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -33,14 +32,12 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
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,
Expand Down

0 comments on commit 9906020

Please sign in to comment.