diet-guard/app/lib/services/background_check_service.dart
Krzysztof kuhy Rudnicki 77468b1efd
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
Bring the Flutter app's dependencies up to latest stable
Split out from the free-day change only by sequence -- diet-guard's
pre-push CI mirror runs the freshness gate over --all-files, so these
were already blocking a push before that work started.

permission_handler 13.0.1 -> 13.0.2 and workmanager 0.10.9 -> 0.10.10
are patch bumps. very_good_analysis ^10.3.0 -> ^11.0.0 is the major one,
and it newly flags 8 async_return_with_no_await sites across the desktop
wrapper and the sync/Firebase services.

Each is now `return await`, not a suppression. The rule is right in every
one of these cases: without the await the future escapes the enclosing
async function, so a rejection surfaces at the caller with a stack trace
that no longer points at the code that made the call.
background_check_service.dart:33 is the clearest example -- its own
comment says the push "is retried with backoff rather than silently
dropped", which is only true if the failure happens inside the function.

Nothing in CI or pre-commit runs `flutter analyze`, so this would not
have failed anything. Leaving a newly-red analyzer for the next person to
find is how a repo stops being analyzable at all.

flutter analyze clean, 706 Flutter tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 15:25:33 +02:00

43 lines
1.7 KiB
Dart

/// WorkManager wiring for the periodic due-slot check (Android/iOS only).
///
/// Registered as a 15-minute periodic task (WorkManager's periodic floor)
/// rather than four fixed exact alarms -- more robust against OEM
/// background-kill behavior, at the cost of ±15 min precision (accepted; see
/// the project plan). Deliberately **not** requesting `SCHEDULE_EXACT_ALARM`
/// for this reason -- don't reach for it to "fix" perceived lateness.
///
/// The check itself lives in `due_slot_check.dart` so it stays free of the
/// `workmanager` import, which has no web implementation.
library;
import 'package:diet_guard_app/services/background_sync_service.dart';
import 'package:diet_guard_app/services/due_slot_check.dart';
import 'package:workmanager/workmanager.dart';
/// Unique WorkManager task name for the periodic due-slot check.
const String backgroundCheckTaskName = 'diet_guard.background_check';
/// WorkManager entry point invoked by the OS on each periodic tick.
///
/// Deliberately thin: all logic lives in [checkAndNotify] so it stays unit
/// testable. This dispatcher itself is integration-only -- manually
/// smoke-tested on-device (see the project plan's verification section),
/// not chased for unit coverage.
// coverage:ignore-start
@pragma('vm:entry-point')
void backgroundCheckCallbackDispatcher() {
Workmanager().executeTask((taskName, inputData) async {
if (taskName == syncPushTaskName) {
// Return the push's own success flag so a still-offline / failed push
// is retried with backoff rather than silently dropped.
return await backgroundSyncPush();
}
if (taskName == backgroundCheckTaskName) {
await checkAndNotify();
}
return true;
});
}
// coverage:ignore-end