Skip to content

fix: timer loading — zero duration, start failure, and keepScreenOn sync#10

Merged
nbucic merged 3 commits into
masterfrom
fix/timer-loading-and-keepscreenon
Jul 16, 2026
Merged

fix: timer loading — zero duration, start failure, and keepScreenOn sync#10
nbucic merged 3 commits into
masterfrom
fix/timer-loading-and-keepscreenon

Conversation

@nbucic

@nbucic nbucic commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Root cause

When a program has no phases:

  • Program::totalDuration() returns 0 → programTotalDuration = 0
  • TimerRunner::start() throws RuntimeException("Program has no phases.") — this exception silently rolls back the Livewire response, so the UI never updates and the Start button appears to do nothing

This can happen when a user creates a program and navigates to the timer without adding any phases.

Changes

TimerScreen::start() — guard against empty phases

Instead of propagating an exception from TimerRunner::start(), the action now returns early when phases are empty. State is left untouched and the blade renders the "no phases" notice.

timer-screen.blade.php — no-phases notice

When the timer is idle and $phases is empty, the Start button is replaced with an amber warning: "No phases — edit this program to add at least one phase before starting." The Edit button in the secondary row is still shown so the user can fix the program immediately.

ProgramEditor::totalDuration() — match timer behaviour

The editor's preview summed every phase's cooldown, including the last phase. But the timer skips the last phase's cooldown (goes straight to COMPLETED after the final rep). This made the preview total higher than the actual run duration for any program with a last-phase cooldown. Fixed to subtract the last phase's cooldown, matching Program::totalDuration().

TimerScreen::loadProgram() / requestSettings() — forward keepScreenOn

Both methods dispatch settingsLoaded to sync JS audio state, but neither included keepScreenOn. The fix/tts-wakelock-caching commit added a settingsLoaded JS handler that reads keepScreenOn to gate wake-lock acquisition. Without it, the wake lock could be stuck in the wrong state whenever a program was loaded or settings were refreshed. Both dispatches now include keepScreenOn: $this->keepScreenOn.

Test plan

  • Open a program that has no phases → timer screen shows amber "No phases" notice, no Start button
  • Edit the same program, add a phase, save → redirected to timer, Start button visible, timer starts normally
  • Start a program with phases → 5-second PREPARE countdown plays, timer counts down correctly
  • Open program editor on a program whose last phase has a non-zero cooldown → preview total matches the actual timer run (cooldown excluded)
  • Open settings, toggle Keep Screen On, save → confirm the timer respects the new value on next program load

https://claude.ai/code/session_018ofANSCtBHs5P8rvvJ9Mh3

Base automatically changed from fix/tts-wakelock-caching to master April 16, 2026 08:04
@nbucic

nbucic commented Apr 16, 2026

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

nbucic added 2 commits July 16, 2026 20:56
…bundle

- Import audioTTS package module directly instead of relying on window.AndroidTTS bridge
- Add 'database' to NativePHP bundled paths so SQLite DB is included on device
- Fix countdown label off-by-one (show remaining - 1 during countdown)
- Allow cooldown input on last phase (was incorrectly disabled); improve helper text
- Add "Demo with no phases" seed program for edge-case testing
- Clean up debug logging, debugger statements, and unused imports in Settings/audio
- Gitignore AI tooling files (.claude, CLAUDE.md, .agents, etc.)
@nbucic
nbucic force-pushed the fix/timer-loading-and-keepscreenon branch from 4e53e04 to 19d71fb Compare July 16, 2026 20:57
@nbucic
nbucic merged commit e6734e7 into master Jul 16, 2026
@nbucic
nbucic deleted the fix/timer-loading-and-keepscreenon branch July 16, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant