Skip to content

Commit 7e3e5f1

Browse files
committed
refactor: update bugsee manager state variables
1 parent a2a88db commit 7e3e5f1

2 files changed

Lines changed: 47 additions & 33 deletions

File tree

src/app/lib/business/bugsee/bugsee_manager.dart

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@ abstract interface class BugseeManager {
1818
required BugseeRepository bugseeRepository,
1919
}) = _BugseeManager;
2020

21-
bool get isRequireRestart;
22-
23-
bool get bugseeIsEnabled;
24-
bool get captureVideoIsEnabled;
25-
bool get isValidConfiguration;
21+
/// indicate if the app require a restart to reactivate the bugsee configurations
22+
///
23+
/// `true` only if `isConfigurationValid == true` and bugsee is turned on
24+
bool get isRestartRequired;
25+
26+
/// indicate if bugsee is enabled or not
27+
/// by default bugsee is enabled if `isConfigurationValid == true`.
28+
bool get isBugseeEnabled;
29+
30+
/// indicate whether video capturing is enabled or not.
31+
/// enabled by default if `isBugseeEnabled == true`.
32+
///
33+
/// cannot be true if `isBugseeEnabled == false`.
34+
bool get isVideoCaptureEnabled;
35+
36+
/// indicate if bugsee configuration is valid
37+
/// config is valid if app in release mode and the provided token is valid
38+
/// following the [bugseeTokenFormat] regex.
39+
bool get isConfigurationValid;
2640

2741
/// initialize bugsee with given token
2842
/// bugsee is not available in debug mode
@@ -66,16 +80,16 @@ final class _BugseeManager implements BugseeManager {
6680
});
6781

6882
@override
69-
bool isRequireRestart = false;
83+
bool isRestartRequired = false;
7084

7185
@override
72-
bool bugseeIsEnabled = false;
86+
bool isBugseeEnabled = false;
7387

7488
@override
75-
late bool captureVideoIsEnabled = false;
89+
late bool isVideoCaptureEnabled = false;
7690

7791
@override
78-
bool isValidConfiguration = true;
92+
bool isConfigurationValid = true;
7993

8094
late bool _isBugSeeInitialized;
8195
BugseeLaunchOptions? launchOptions;
@@ -91,14 +105,14 @@ final class _BugseeManager implements BugseeManager {
91105
_isBugSeeInitialized = false;
92106

93107
if (kDebugMode) {
94-
isValidConfiguration = false;
108+
isConfigurationValid = false;
95109
logger.i("BUGSEE: deactivated in debug mode");
96110
return;
97111
}
98112

99113
if (bugseeToken == null ||
100114
!RegExp(bugseeTokenFormat).hasMatch(bugseeToken)) {
101-
isValidConfiguration = false;
115+
isConfigurationValid = false;
102116
logger.i(
103117
"BUGSEE: token is null or invalid, bugsee won't be initialized",
104118
);
@@ -109,8 +123,8 @@ final class _BugseeManager implements BugseeManager {
109123
await launchBugseeLogger(bugseeToken);
110124
}
111125

112-
bugseeIsEnabled = _isBugSeeInitialized;
113-
captureVideoIsEnabled = _isBugSeeInitialized &&
126+
isBugseeEnabled = _isBugSeeInitialized;
127+
isVideoCaptureEnabled = _isBugSeeInitialized &&
114128
(bugseeConfigurationData.isVideoCaptureEnabled ?? true);
115129
}
116130

@@ -144,7 +158,7 @@ final class _BugseeManager implements BugseeManager {
144158
required Exception exception,
145159
StackTrace? stackTrace,
146160
}) async {
147-
if (bugseeIsEnabled) {
161+
if (isBugseeEnabled) {
148162
await Bugsee.logException(exception, stackTrace);
149163
}
150164
}
@@ -154,30 +168,30 @@ final class _BugseeManager implements BugseeManager {
154168
required Exception exception,
155169
StackTrace? stackTrace,
156170
}) async {
157-
if (bugseeIsEnabled) {
171+
if (isBugseeEnabled) {
158172
await Bugsee.logUnhandledException(exception);
159173
}
160174
}
161175

162176
@override
163-
Future<void> setIsBugseeEnabled(bool isBugseeEnabled) async {
164-
if (isValidConfiguration) {
177+
Future<void> setIsBugseeEnabled(bool value) async {
178+
if (isConfigurationValid) {
179+
isBugseeEnabled = value;
165180
await bugseeRepository.setIsBugseeEnabled(isBugseeEnabled);
166181

167-
isRequireRestart = _isBugSeeInitialized && isBugseeEnabled;
168-
bugseeIsEnabled = isBugseeEnabled;
169-
captureVideoIsEnabled = bugseeIsEnabled;
182+
isRestartRequired = _isBugSeeInitialized && isBugseeEnabled;
183+
isVideoCaptureEnabled = isBugseeEnabled;
170184

171-
if (!isRequireRestart) {
185+
if (!isRestartRequired) {
172186
await Bugsee.stop();
173187
}
174188
}
175189
}
176190

177191
@override
178-
Future<void> setIsVideoCaptureEnabled(bool isVideoCaptureEnabled) async {
179-
if (bugseeIsEnabled) {
180-
captureVideoIsEnabled = isVideoCaptureEnabled;
192+
Future<void> setIsVideoCaptureEnabled(bool value) async {
193+
if (isBugseeEnabled) {
194+
isVideoCaptureEnabled = value;
181195
await bugseeRepository.setIsVideoCaptureEnabled(isVideoCaptureEnabled);
182196
if (!isVideoCaptureEnabled) {
183197
await Bugsee.pause();
@@ -189,7 +203,7 @@ final class _BugseeManager implements BugseeManager {
189203

190204
@override
191205
Future<void> showCaptureLogReport() async {
192-
if (bugseeIsEnabled) {
206+
if (isBugseeEnabled) {
193207
await Bugsee.showReportDialog();
194208
}
195209
}

src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
2323
@override
2424
void initState() {
2525
super.initState();
26-
isConfigEnabled = bugseeManager.bugseeIsEnabled;
27-
isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled;
28-
requireRestart = bugseeManager.isRequireRestart;
26+
isConfigEnabled = bugseeManager.isBugseeEnabled;
27+
isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled;
28+
requireRestart = bugseeManager.isRestartRequired;
2929
}
3030

3131
@override
@@ -34,7 +34,7 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
3434
children: [
3535
Column(
3636
children: [
37-
if (!bugseeManager.isValidConfiguration)
37+
if (!bugseeManager.isConfigurationValid)
3838
Container(
3939
color: const Color.fromARGB(170, 255, 0, 0),
4040
child: const Text(
@@ -68,9 +68,9 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
6868
onChanged: (value) async {
6969
await bugseeManager.setIsBugseeEnabled(value);
7070
setState(() {
71-
isConfigEnabled = bugseeManager.bugseeIsEnabled;
72-
isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled;
73-
requireRestart = bugseeManager.isRequireRestart;
71+
isConfigEnabled = bugseeManager.isBugseeEnabled;
72+
isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled;
73+
requireRestart = bugseeManager.isRestartRequired;
7474
});
7575
},
7676
),
@@ -80,7 +80,7 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
8080
onChanged: (value) async {
8181
await bugseeManager.setIsVideoCaptureEnabled(value);
8282
setState(() {
83-
isCaptureVideoEnabled = bugseeManager.captureVideoIsEnabled;
83+
isCaptureVideoEnabled = bugseeManager.isVideoCaptureEnabled;
8484
});
8585
},
8686
),

0 commit comments

Comments
 (0)