wake-alarm/phone_app/lib/screens/session_checkin.dart
Krzysztof kuhy Rudnicki c3c129b068 Make the morning session the carrot: earn 11:00 by finishing it in time
On 2026-09-19 the phone was powered off after the bathroom tag and nothing
on the PC noticed: every finished session was published and nothing read
it. Now wake-alarm distils the phone's morning into an HMAC-signed
~/.local/state/wake_alarm/morning_session.json (wake-alarm-session.timer,
07:00-11:00 every 2 min) that screen-locker and leetcode-guard read to
defer their locks -- provisionally until min(start + 90 min, 09:30) while
the session is live, until 11:00 once it completed inside that cutoff,
and not at all for a session finished later (the phone switched on at
noon completes the legs then; that must un-lock nothing).

The phone publishes the session at start as well as at finish
(current_session, cleared with the finish stamp), so the PC can tell
"started, not finished" from "never started". A required 1-5 energy tap
joins the weigh-in and ships as latest_energy with a PC reader mirroring
_weight (the shared half is _field_reader).

Also fixes the vmbox harness, red since the 2026-09-11 home-tidy: the
guest tree lives at ~/wake-alarm, and the INSTALL-OK grep matched vm's
echo of the command line. Takes Flutter 3.47.5.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tp54ewdXRLaimUuT8LgYyn
2026-09-19 16:40:51 +02:00

60 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:wake_alarm_sync/services/morning_session.dart';
import 'package:wake_alarm_sync/services/session_rules.dart';
import 'package:wake_alarm_sync/services/weight_entry.dart';
/// What a check-in attempt came to: the status line, and whether it stuck.
typedef CheckInResult = ({String detail, bool recorded});
/// The weigh-in field's state and the energy tap, kept out of the screen.
///
/// Holds what used to be four fields on `_SessionScreenState`: the text
/// controller, the last weight (for the jump check), the value awaiting a
/// retyped confirmation, and now the energy level. [submit] applies the
/// rules in order — energy first, since it is the cheaper thing to fix —
/// and only touches the session when everything passed.
class SessionCheckIn {
/// The weight field's controller; disposed by [dispose].
final TextEditingController input = TextEditingController();
/// The previous morning's weight, for the plausibility jump check.
double? lastWeight;
/// A weight awaiting a retyped confirmation, if the jump was large.
double? confirming;
/// The tapped energy level, or null.
int? energy;
/// Validates and, if everything passes, records the check-in on [session].
CheckInResult submit(MorningSession session, DateTime now) {
final level = energy;
if (level == null) {
return (
detail: 'Tap your energy ($minEnergy-$maxEnergy) first',
recorded: false,
);
}
final check = checkWeight(
input.text,
last: lastWeight,
confirming: confirming,
);
if (!check.accepted) {
confirming = check.verdict == WeightVerdict.needsConfirm
? check.kg
: null;
return (detail: check.detail, recorded: false);
}
confirming = null;
input.clear();
return (
detail: session.enterCheckIn(check.kg!, level, now),
recorded: true,
);
}
/// Releases the controller.
void dispose() => input.dispose();
}