[mob][photos] Internally keep track of MLController status

This commit is contained in:
laurenspriem
2024-05-15 11:33:35 +05:30
parent b2c274e73b
commit 6ab1371077
2 changed files with 15 additions and 12 deletions

View File

@@ -22,11 +22,9 @@ class MachineLearningController {
bool _isDeviceHealthy = true;
bool _isUserInteracting = true;
bool _isRunningML = false;
bool _canRunML = false;
late Timer _userInteractionTimer;
get canRunML => _isDeviceHealthy && !_isUserInteracting;
void init() {
if (Platform.isAndroid) {
_startInteractionTimer();
@@ -37,6 +35,7 @@ class MachineLearningController {
});
} else {
// Always run Machine Learning on iOS
_canRunML = true;
Bus.instance.fire(MachineLearningControlEvent(true));
}
}
@@ -54,9 +53,9 @@ class MachineLearningController {
}
void _fireControlEvent() {
final shouldRunML = canRunML;
if (shouldRunML != _isRunningML) {
_isRunningML = shouldRunML;
final shouldRunML = _isDeviceHealthy && !_isUserInteracting;
if (shouldRunML != _canRunML) {
_canRunML = shouldRunML;
_logger.info(
"Firing event with device health: $_isDeviceHealthy and user interaction: $_isUserInteracting",
);