wake-alarm/phone_app/lib/services/session_notice.dart
Krzysztof kuhy Rudnicki 52c3ff5f1e
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Make wake-alarm text-free (textgate-rework)
Todo: 364208fc
2026-11-11 12:45:10 +01:00

54 lines
2.0 KiB
Dart

import 'package:wake_alarm_sync/services/alarm_scheduler.dart';
import 'package:wake_alarm_sync/services/morning_session.dart';
import 'package:wake_alarm_sync/services/session_rules.dart';
/// Keeps the native side pointed at the live leg.
///
/// One call re-arms the deadline (`armReRing`) and rewrites the native
/// session record behind the launcher redirect and the ongoing notification
/// (`updateSessionNotice`). They are one operation on purpose: a leg whose
/// deadline moved but whose notice did not would show a countdown to an
/// instant nothing rings at, and the reverse would let the notification
/// promise a ring the alarm never arms.
///
/// Called on every change to the session, never per tick -- the countdown
/// is the notification's own.
///
/// A session that is over gets no notice: the finish path clears the record
/// and the notification, and this must not race it back into existence --
/// the tick that noticed the last leg pass ran `_finish` while the tag's
/// own commit was still on its way here (emulator, 2026-09-17), and the
/// stale "Done" record then redirected the next launch into a second
/// session for the day.
Future<void> pointNativeAtLeg(
AlarmScheduler scheduler,
MorningSession session,
) async {
final deadline = session.nextDeadline();
await scheduler.armReRing(deadline);
if (!session.isActive) return;
await scheduler.updateSessionNotice(
date: session.date,
label: noticeLabel(session),
deadline: deadline,
);
}
/// The notification's one line: glyph + position count, with a running-clock
/// marker when the re-ring was spent.
String noticeLabel(MorningSession session) {
final leg = session.currentLeg!;
final glyphs = <SessionLeg, String>{
SessionLeg.bathroomIn: '🛁',
SessionLeg.showerDone: '🚿',
SessionLeg.dressed: '👕',
SessionLeg.atDesk: '🪑',
};
final glyph = glyphs[leg] ?? '•';
var text = '$glyph ${leg.index + 1}/${SessionLeg.values.length}';
if (session.deadlineRung.contains(leg)) {
text += ' ⏳';
}
return text;
}