Compare commits

..

No commits in common. "64c6105dbe0808855efcf9bc2ac54c92cb316a95" and "95adc8699cbc822ddad4ae1089e48b99dca0ba7f" have entirely different histories.

6 changed files with 14 additions and 38 deletions

View File

@ -38,16 +38,11 @@ _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 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).
``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``.
"""
parts: list[str] = []
if after is None:
@ -61,8 +56,6 @@ 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}"
@ -100,8 +93,7 @@ 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, reward)
body = credit_body(before, after)
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, first_minutes
from screen_locker._earned import extra_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,12 +160,7 @@ class WorkoutCreditMixin:
after = self._read_shutdown_config()
if slot is not CreditSlot.NONE:
reward = (
first_minutes(earned_time.WORKOUT, day)
if first_counted_today
else extra
)
self._notify_credit(before, after, reward)
self._notify_credit(before, after)
return WorkoutCreditResult(
shutdown_adjusted=shutdown_adjusted,
@ -178,7 +173,6 @@ 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.
@ -188,7 +182,7 @@ class WorkoutCreditMixin:
batch uncredited, so every exception is logged and dropped here.
"""
try:
_credit_notify.notify_workout_credit(before, after, reward)
_credit_notify.notify_workout_credit(before, after)
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,16 +55,6 @@ 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"
@ -142,8 +132,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, 1080, 0), (0, 1318, 0), 120)
send.assert_called_once_with(_credit_notify.TITLE, f"{_SHUTDOWN} 21:58 (+2h)")
assert _real_notify((0, 1200, 0), (0, 1260, 0))
send.assert_called_once_with(_credit_notify.TITLE, f"{_SHUTDOWN} 21:00 (+1h)")
class TestCreditSideOfTheNotifier:
@ -159,7 +149,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, None)
locker._notify_credit(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), 120)
notify.assert_called_once_with(_START, (1320, 1320, 300))
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_with(_START, (1260, 1260, 300), 60)
notify.assert_called_once()
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: "7d37d69ded3028af4f22531a0097a3baa478a384dff2e23e873707c93df3b704"
sha256: fac349e7361f80591a0cedff03548f807282c9faee9fc6192763166e5f81def2
url: "https://pub.dev"
source: hosted
version: "23.0.3"
version: "23.0.2"
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.3
flutter_local_notifications: 23.0.2
# The run map and its tile disk cache.
flutter_map: 8.3.2
flutter_map_cache: 2.1.2