[mob][photos] Don't pause ML when in ML settings page

This commit is contained in:
laurenspriem
2024-06-04 11:33:13 +05:30
parent 9db9a18e3e
commit 4133764cb0
2 changed files with 64 additions and 25 deletions

View File

@@ -24,6 +24,7 @@ class MachineLearningController {
bool _isDeviceHealthy = true;
bool _isUserInteracting = true;
bool _canRunML = false;
bool mlInteractionOverride = false;
late Timer _userInteractionTimer;
bool get isDeviceHealthy => _isDeviceHealthy;
@@ -61,13 +62,23 @@ class MachineLearningController {
_resetTimer();
}
bool _canRunGivenUserInteraction() {
return (Platform.isIOS ? true : !_isUserInteracting) ||
mlInteractionOverride;
}
void forceOverrideML({required bool turnOn}) {
_logger.info("Forcing to turn on ML: $turnOn");
mlInteractionOverride = turnOn;
_fireControlEvent();
}
void _fireControlEvent() {
final shouldRunML =
_isDeviceHealthy && (Platform.isAndroid ? !_isUserInteracting : true);
final shouldRunML = _isDeviceHealthy && _canRunGivenUserInteraction();
if (shouldRunML != _canRunML) {
_canRunML = shouldRunML;
_logger.info(
"Firing event with $shouldRunML, device health: $_isDeviceHealthy and user interaction: $_isUserInteracting",
"Firing event: $shouldRunML (device health: $_isDeviceHealthy, user interaction: $_isUserInteracting, mlInteractionOverride: $mlInteractionOverride)",
);
Bus.instance.fire(MachineLearningControlEvent(shouldRunML));
}