Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat: add device health listener event

Prateek Sunal6ce34c1b321f
diff --git a/mobile/apps/photos/lib/events/device_health_changed_event.dart b/mobile/apps/photos/lib/events/device_health_changed_event.dart
new file mode 100644
index 0000000000..4451b37bad
--- /dev/null
+++ b/mobile/apps/photos/lib/events/device_health_changed_event.dart
@@ -0,0 +1,7 @@
+import "package:photos/events/event.dart";
+
+class DeviceHealthChangedEvent extends Event {
+ final bool isHealthy;
+
+ DeviceHealthChangedEvent(this.isHealthy);
+}
diff --git a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
index 62b73a443c..edfad0752f 100644
--- a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
@@ -8,6 +8,7 @@ import "package:flutter/foundation.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/compute_control_event.dart";
+import "package:photos/events/device_health_changed_event.dart";
import "package:thermal/thermal.dart";
enum ComputeRunState {
@@ -47,6 +48,13 @@ class ComputeController {
bool get isDeviceHealthy => _isDeviceHealthy;
+ void _setDeviceHealth(bool healthy) {
+ if (_isDeviceHealthy == healthy) return;
+ _isDeviceHealthy = healthy;
+ _logger.info("Device health changed: $healthy");
+ Bus.instance.fire(DeviceHealthChangedEvent(healthy));
+ }
+
ComputeController() {
_logger.info('ComputeController constructor');
init();
@@ -232,23 +240,25 @@ class ComputeController {
void _onAndroidBatteryStateUpdate(AndroidBatteryInfo? batteryInfo) {
_androidLastBatteryInfo = batteryInfo;
_logger.info("Battery info: ${batteryInfo!.toJson()}");
- _isDeviceHealthy = _computeIsAndroidDeviceHealthy();
+ _setDeviceHealth(_computeIsAndroidDeviceHealthy());
_fireControlEvent();
}
void _oniOSBatteryStateUpdate(IosBatteryInfo? batteryInfo) {
_iosLastBatteryInfo = batteryInfo;
_logger.info("Battery info: ${batteryInfo!.toJson()}");
- _isDeviceHealthy = _computeIsiOSDeviceHealthy();
+ _setDeviceHealth(_computeIsiOSDeviceHealthy());
_fireControlEvent();
}
void _onThermalStateUpdate(ThermalStatus? thermalStatus) {
_lastThermalStatus = thermalStatus;
_logger.info("Thermal status: $thermalStatus");
- _isDeviceHealthy = Platform.isAndroid
- ? _computeIsAndroidDeviceHealthy()
- : _computeIsiOSDeviceHealthy();
+ _setDeviceHealth(
+ Platform.isAndroid
+ ? _computeIsAndroidDeviceHealthy()
+ : _computeIsiOSDeviceHealthy(),
+ );
_fireControlEvent();
}
diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dart
index b6c3d49ea3..dc3bea8445 100644
--- a/mobile/apps/photos/lib/services/video_preview_service.dart
+++ b/mobile/apps/photos/lib/services/video_preview_service.dart
@@ -18,7 +18,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
import "package:photos/db/upload_locks_db.dart";
-import "package:photos/events/compute_control_event.dart";
+import "package:photos/events/device_health_changed_event.dart";
import "package:photos/events/sync_status_update_event.dart";
import "package:photos/events/video_preview_state_changed_event.dart";
import "package:photos/events/video_streaming_changed.dart";
@@ -83,10 +83,10 @@ class VideoPreviewService {
}
});
- Bus.instance.on<ComputeControlEvent>().listen((event) {
- if (!computeController.isDeviceHealthy) {
+ Bus.instance.on<DeviceHealthChangedEvent>().listen((event) {
+ if (!event.isHealthy) {
stopSafely("device unhealthy").ignore();
- } else if (event.shouldRun && isVideoStreamingEnabled) {
+ } else if (isVideoStreamingEnabled) {
_logger.info("Device healthy, resuming stream processing");
queueFiles(duration: Duration.zero);
}