Compare commits

...

2 Commits

Author SHA1 Message Date
64c6105dbe Bump flutter_local_notifications to 23.0.3
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 }}) (flutter, flutter-analyze, ) (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,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWLoUxxSPf1m8KUVo8
2026-11-18 20:55:42 +01:00
7539a82429 Show the run's reward in the credit toast
A late credit moves shutdown from an hour already past to the run's
end plus its reward, so the toast read "+3h58m" for a 2h run
(18:00 -> 21:58, 2026-11-18). The delta is now capped at the reward
the credit earned: still the real move when the ceiling cut it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWLoUxxSPf1m8KUVo8
2026-11-18 20:53:52 +01:00
6 changed files with 38 additions and 14 deletions

View File

@ -38,11 +38,16 @@ _NOTIFY_TIMEOUT_SECONDS: Final = 5
def credit_body(
before: tuple[int, int, int] | None,
after: tuple[int, int, int] | None,
reward: int | None = None,
) -> str:
"""``⏻ 23:00 (+2h)`` -- whichever parts are known.
``before``/``after`` are the shutdown config around the credit; the delta
is tonight's actual move, so a capped or rest-day credit shows ``+0h``.
``before``/``after`` are the shutdown config around the credit. The delta
is what the workout earned: tonight's actual move, so a capped or rest-day
credit shows ``+0h``, but never more than ``reward``. A late credit moves
the shutdown from an hour already past to the run's end plus the reward
(:mod:`._late_credit`); that jump is not what the run earned
(18:00 -> 21:58 read "+3h58m" for a 2h run, 2026-11-18).
"""
parts: list[str] = []
if after is None:
@ -56,6 +61,8 @@ def credit_body(
text = f"{_SHUTDOWN} {hhmm(tonight)}"
if before is not None:
moved = max(0, tonight - tonight_minutes(before, day))
if reward is not None:
moved = min(moved, reward)
text += f" (+{span(moved)})"
parts.append(text)
return " \N{MIDDLE DOT} ".join(parts) or "\N{CHECK MARK}"
@ -93,7 +100,8 @@ def send_notification(title: str, body: str) -> bool:
def notify_workout_credit(
before: tuple[int, int, int] | None,
after: tuple[int, int, int] | None,
reward: int | None,
) -> bool:
"""Notify a newly earned workout credit. Never raises."""
body = credit_body(before, after)
body = credit_body(before, after, reward)
return send_notification(TITLE, body)

View File

@ -20,7 +20,7 @@ from screen_locker import _credit_notify
from screen_locker._constants import SHUTDOWN_BASE_FILE
from screen_locker._credit_slot import CreditSlot, credit_slot, locked_shutdown_state
from screen_locker._day import today_str
from screen_locker._earned import extra_minutes
from screen_locker._earned import extra_minutes, first_minutes
from screen_locker._rest_day import is_rest_day
from screen_locker._weekly_check import COUNTED_WORKOUT_TYPES, count_weekly_workouts
from screen_locker._workout_ledger import entry_done_at
@ -160,7 +160,12 @@ class WorkoutCreditMixin:
after = self._read_shutdown_config()
if slot is not CreditSlot.NONE:
self._notify_credit(before, after)
reward = (
first_minutes(earned_time.WORKOUT, day)
if first_counted_today
else extra
)
self._notify_credit(before, after, reward)
return WorkoutCreditResult(
shutdown_adjusted=shutdown_adjusted,
@ -173,6 +178,7 @@ class WorkoutCreditMixin:
self,
before: tuple[int, int, int] | None,
after: tuple[int, int, int] | None,
reward: int | None,
) -> None:
"""Pop the "Workout credited" notification; never fails the credit.
@ -182,7 +188,7 @@ class WorkoutCreditMixin:
batch uncredited, so every exception is logged and dropped here.
"""
try:
_credit_notify.notify_workout_credit(before, after)
_credit_notify.notify_workout_credit(before, after, reward)
except Exception: # pylint: disable=broad-exception-caught # notification must never fail the credit
_logger.exception(
"Workout credit notification failed — the credit itself is "

View File

@ -55,6 +55,16 @@ class TestCreditBody:
body = _credit_notify.credit_body((0, 1380, 0), (0, 1320, 0))
assert body == f"{_SHUTDOWN} 22:00 (+0h)"
def test_a_late_credit_shows_the_reward_not_the_jump(self) -> None:
"""18:00 -> 21:58 after a run ending 19:58: the toast says +2h, not +3h58m."""
body = _credit_notify.credit_body((0, 1080, 0), (0, 1318, 0), reward=120)
assert body == f"{_SHUTDOWN} 21:58 (+2h)"
def test_a_ceiling_cut_reward_shows_what_was_left(self) -> None:
"""A 2h reward that met the 23:00 ceiling after 1h shows +1h."""
body = _credit_notify.credit_body((0, 1320, 0), (0, 1380, 0), reward=120)
assert body == f"{_SHUTDOWN} 23:00 (+1h)"
def test_unknown_before_drops_the_delta(self) -> None:
"""Without the old config there is no move to show."""
assert _credit_notify.credit_body(None, (0, 1320, 0)) == f"{_SHUTDOWN} 22:00"
@ -132,8 +142,8 @@ def test_notify_workout_credit_sends_the_composed_body() -> None:
with (
patch(f"{_MOD}.send_notification", return_value=True) as send,
):
assert _real_notify((0, 1200, 0), (0, 1260, 0))
send.assert_called_once_with(_credit_notify.TITLE, f"{_SHUTDOWN} 21:00 (+1h)")
assert _real_notify((0, 1080, 0), (0, 1318, 0), 120)
send.assert_called_once_with(_credit_notify.TITLE, f"{_SHUTDOWN} 21:58 (+2h)")
class TestCreditSideOfTheNotifier:
@ -149,7 +159,7 @@ class TestCreditSideOfTheNotifier:
"""Anything the notifier raises is logged at ERROR and dropped."""
locker = create_locker(mock_tk, tmp_path)
with patch(f"{_MOD}.notify_workout_credit", side_effect=KeyError("x")):
locker._notify_credit(None, None)
locker._notify_credit(None, None, None)
assert any(
r.levelno == logging.ERROR and "notification failed" in r.getMessage()
for r in caplog.records

View File

@ -129,7 +129,7 @@ class TestSlotCreditMinutes:
result, notify = _credit(locker, [])
assert result.shutdown_adjusted is True
assert locker._read_shutdown_config() == (1320, 1320, 300)
notify.assert_called_once_with(_START, (1320, 1320, 300))
notify.assert_called_once_with(_START, (1320, 1320, 300), 120)
def test_distinct_slot_earns_one_hour(
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
@ -139,7 +139,7 @@ class TestSlotCreditMinutes:
result, notify = _credit(locker, [_entry("phone_verified")])
assert result.extra_bonus_delta == 60
assert locker._read_shutdown_config() == (1260, 1260, 300)
notify.assert_called_once()
notify.assert_called_once_with(_START, (1260, 1260, 300), 60)
def test_same_slot_earns_nothing_and_warns(
self,

View File

@ -436,10 +436,10 @@ packages:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: fac349e7361f80591a0cedff03548f807282c9faee9fc6192763166e5f81def2
sha256: "7d37d69ded3028af4f22531a0097a3baa478a384dff2e23e873707c93df3b704"
url: "https://pub.dev"
source: hosted
version: "23.0.2"
version: "23.0.3"
flutter_local_notifications_linux:
dependency: transitive
description:

View File

@ -34,7 +34,7 @@ dependencies:
flutter_foreground_task: 11.0.3
# The break-end alert itself, on its own high-importance channel so the OS
# rings even if the Flutter isolate is busy.
flutter_local_notifications: 23.0.2
flutter_local_notifications: 23.0.3
# The run map and its tile disk cache.
flutter_map: 8.3.2
flutter_map_cache: 2.1.2