Keep the timer notification in the background; fix review findings #20

Merged
berkay merged 1 commit from review-fixes into main 2026-11-10 18:33:02 +03:00
Owner

Requested by Berkay · project thread

Timer notification disappears in the background

Root cause: ForegroundTaskOptions(stopWithTask: true). In flutter_foreground_task 11.0.3 this option also installs TrackVisibilityUtils, which calls stopForegroundService() in onActivityPaused once no activity is resumed, i.e. as soon as the app goes to the background. After that every updateService returned ServiceRequestFailure(ServiceNotStartedException), which was ignored, so the notification never came back (and the process lost its foreground status and wake lock).

Fix: leave stopWithTask unset (the manifest's android:stopWithTask="true" still stops the service when the app is swiped from recents), allowAutoRestart: false, read the plugin's result values, and try to start the service again (at most every 10 s) when an update finds it gone.

Review findings fixed

  • Notification shows Paused · 0:55 · Round 1 right away (it was stuck on the last time).
  • No state rebuilds while paused; screen wake lock released while paused.
  • Skip round from the pause menu keeps the 3-2-1 countdown.
  • Random mode PREV walks back through the round.
  • Double tap on PAUSE opens a single sheet.
  • Each finished round is checkpointed to history under the session id; discard removes it.
  • Finishing an edited, unsaved workout updates only lastDoneAt of the stored copy.
  • Unreadable records are skipped (logged) instead of emptying the list; settings fall back to defaults.
  • Database open failure shows an error screen with retry instead of hanging on the splash.
  • Combo delete + workout cleanup in one transaction.
  • TTS: checks setLanguage (en-US, en-GB, en), 5 s timeout, falls back to the knock cue, warns once on the session screen; retried on next start.
  • just_audio play() errors caught.
  • Weekly goal week bounds use calendar days (DST).

Tests

flutter analyze clean, flutter test 90/90 (6 new: pause notification + screen, checkpoints, edited workout, corrupt records, skip-round countdown, random PREV). Not tested on a device; no APK built.

🤖 Generated with Claude Code

https://claude.ai/code/session_015s4aKptMeqctAXfhFSKWNs

<!-- claude-projects-attribution --> _Requested by **Berkay** · [project thread](https://claude.ai/code/project/chan_01T5Cs4GeJAnhjXKSJKvCDa2?thread=cmsg_01T5Cs4GeJAnhjXKSJKvCDa2NLD5V8zfPnM9LA7HzDp3zu)_ ## Timer notification disappears in the background Root cause: `ForegroundTaskOptions(stopWithTask: true)`. In flutter_foreground_task 11.0.3 this option also installs `TrackVisibilityUtils`, which calls `stopForegroundService()` in `onActivityPaused` once no activity is resumed, i.e. as soon as the app goes to the background. After that every `updateService` returned `ServiceRequestFailure(ServiceNotStartedException)`, which was ignored, so the notification never came back (and the process lost its foreground status and wake lock). Fix: leave `stopWithTask` unset (the manifest's `android:stopWithTask="true"` still stops the service when the app is swiped from recents), `allowAutoRestart: false`, read the plugin's result values, and try to start the service again (at most every 10 s) when an update finds it gone. ## Review findings fixed - Notification shows `Paused · 0:55 · Round 1` right away (it was stuck on the last time). - No state rebuilds while paused; screen wake lock released while paused. - Skip round from the pause menu keeps the 3-2-1 countdown. - Random mode PREV walks back through the round. - Double tap on PAUSE opens a single sheet. - Each finished round is checkpointed to history under the session id; discard removes it. - Finishing an edited, unsaved workout updates only `lastDoneAt` of the stored copy. - Unreadable records are skipped (logged) instead of emptying the list; settings fall back to defaults. - Database open failure shows an error screen with retry instead of hanging on the splash. - Combo delete + workout cleanup in one transaction. - TTS: checks `setLanguage` (en-US, en-GB, en), 5 s timeout, falls back to the knock cue, warns once on the session screen; retried on next start. - `just_audio` `play()` errors caught. - Weekly goal week bounds use calendar days (DST). ## Tests `flutter analyze` clean, `flutter test` 90/90 (6 new: pause notification + screen, checkpoints, edited workout, corrupt records, skip-round countdown, random PREV). Not tested on a device; no APK built. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015s4aKptMeqctAXfhFSKWNs
The timer notification vanished when the app went to the background:
setting stopWithTask in ForegroundTaskOptions makes
flutter_foreground_task 11 stop the service as soon as every activity
is paused. Leave it unset (the manifest still stops the service when
the app is swiped away), check the plugin's result values, and bring
the service back if it is gone.

Also from the external code review:
- notification shows Paused (with the time) right away
- the screen may sleep while paused; no state rebuilds while paused
- skip round from the pause menu keeps the 3-second countdown
- random PREV steps further back instead of bouncing
- double tap on PAUSE opens one sheet
- each finished round is checkpointed to history (process death)
- finishing an edited, unsaved workout no longer overwrites it
- unreadable records are skipped instead of emptying lists
- database open failure shows an error with retry
- combo delete runs in one transaction
- TTS: check the English voice, fall back to a knock, warn once
- just_audio play() errors are caught
- weekly goal weeks use calendar days (DST)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015s4aKptMeqctAXfhFSKWNs
berkay merged commit 87aa779870 into main 2026-11-10 18:33:02 +03:00
berkay deleted branch review-fixes 2026-11-10 18:33:02 +03:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
berkay/bagdrill!20
No description provided.