|
...
|
...
|
@@ -59,7 +59,7 @@ class AppleHealthRawDataCoreService { |
|
|
|
final StreamController<HealthRawDataUpdatedEvent>
|
|
|
|
_healthDataUpdatedController =
|
|
|
|
StreamController<HealthRawDataUpdatedEvent>.broadcast();
|
|
|
|
Future<void>? _healthDataUpdatedCalculation;
|
|
|
|
Future<bool>? _healthDataUpdatedCalculation;
|
|
|
|
Future<HealthRawStressCalculationResult>? _coreCalculation;
|
|
|
|
List<int> _pendingHealthDataUpdatedTypes = const <int>[];
|
|
|
|
bool _isUploadingHrvResults = false;
|
|
...
|
...
|
@@ -106,14 +106,14 @@ class AppleHealthRawDataCoreService { |
|
|
|
Stream<HealthRawDataUpdatedEvent> get healthDataUpdatedStream =>
|
|
|
|
_healthDataUpdatedController.stream;
|
|
|
|
|
|
|
|
Future<void> onHealthDataUpdated({List<int>? dataTypes}) async {
|
|
|
|
Future<bool> onHealthDataUpdated({List<int>? dataTypes}) async {
|
|
|
|
await _saveNativeCallFlutterChange(dataTypes);
|
|
|
|
if (_healthDataUpdatedCalculation != null) {
|
|
|
|
_pendingHealthDataUpdatedTypes = _mergeHealthDataTypes(
|
|
|
|
_pendingHealthDataUpdatedTypes,
|
|
|
|
dataTypes,
|
|
|
|
);
|
|
|
|
return _healthDataUpdatedCalculation;
|
|
|
|
return _healthDataUpdatedCalculation!;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pendingHealthDataUpdatedTypes = _mergeHealthDataTypes(
|
|
...
|
...
|
@@ -123,7 +123,7 @@ class AppleHealthRawDataCoreService { |
|
|
|
final task = _calculateAndNotifyHealthDataUpdated();
|
|
|
|
_healthDataUpdatedCalculation = task;
|
|
|
|
try {
|
|
|
|
await task;
|
|
|
|
return await task;
|
|
|
|
} finally {
|
|
|
|
if (identical(_healthDataUpdatedCalculation, task)) {
|
|
|
|
_healthDataUpdatedCalculation = null;
|
|
...
|
...
|
@@ -131,14 +131,18 @@ class AppleHealthRawDataCoreService { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _calculateAndNotifyHealthDataUpdated() async {
|
|
|
|
Future<bool> _calculateAndNotifyHealthDataUpdated() async {
|
|
|
|
try {
|
|
|
|
await startCoreCaculate();
|
|
|
|
final result = await startCoreCaculate();
|
|
|
|
final completedDataTypes = _pendingHealthDataUpdatedTypes;
|
|
|
|
await _saveFlutterCaculateFinished(completedDataTypes);
|
|
|
|
_healthDataUpdatedController.add(
|
|
|
|
HealthRawDataUpdatedEvent(dataTypes: completedDataTypes),
|
|
|
|
);
|
|
|
|
return result.hrvStressPoints.isNotEmpty ||
|
|
|
|
result.realtimeStressPoints.isNotEmpty ||
|
|
|
|
result.dailyStressPoints.isNotEmpty ||
|
|
|
|
result.sleepResults.isNotEmpty;
|
|
|
|
} finally {
|
|
|
|
_pendingHealthDataUpdatedTypes = const <int>[];
|
|
|
|
}
|
...
|
...
|
|