Skip to content

Play-time and real-time clocks with pause toggle - #24

Merged
ToothyDev merged 6 commits into
mainfrom
claude/2-clocks
Oct 14, 2026
Merged

ToothyDev merged 6 commits into
mainfrom
claude/2-clocks

Conversation

@ToothyDev

@ToothyDev ToothyDev commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Closes #2

What it does

  • Session play time (src/lib/clock.ts): starts at zero each time LSOS opens and is not saved. Trackers keep their own saved progress, so a total across sessions adds nothing.
  • Opens paused by default. While paused, a hint says to press Start once you've loaded into a GTA Online session, not during loading screens, since that's roughly when the game starts counting. Settings → Clock → "Start tracking play time when LSOS opens" (clock.trackOnOpen, saved) starts it running instead; its hint says loading screens then count too.
  • Clock bar under the header: TRACKING / PAUSED, session play time, the current time and a Start/Pause button.
  • Throttling-proof: each tick adds now - lastTick, never a tick count, so a hidden tab ticking once a minute (Chrome throttling, e.g. while a fullscreen game covers the browser) still counts every second.
  • Long gaps are asked about, not guessed. Gaps up to 5 minutes count. Longer ones come from the browser freezing the tab (Chrome Energy Saver) or the computer sleeping, which the page can't tell apart. They're held and a prompt asks "Were you playing?" with Count it / Skip. Gaps where the clock went backwards count zero.
  • Tracker API (src/lib/clock.svelte.ts): onPlayTime(listener) hands each counted stretch of play time to trackers (every tick, on pause, on close, on a confirmed gap) so they add it to their saved progress. realElapsed(sinceMs, now) covers real-time cooldowns.
  • Saves when hidden or frozen (visibilitychange, freeze) so trackers' progress survives a discarded tab. saveNow writes the current state directly, because the save effect would run too late in a page that is closing. pagehide stops measuring, so time away from a back/forward-cached page isn't counted.
  • State version 2 adds clock: { trackOnOpen }. Version 1 data migrates to false (tested with a stored sample).
  • Decision 008 records all of this and notes that it changes one point of decision 003. README, CLAUDE.md map and Next up → UI: GTA-themed terminal design #3 updated.

Tests

Fake timestamps only: starting paused or tracking, normal run, throttled background tab, gap at and above the threshold, confirming and skipping long gaps, clock set back, pause/resume, leaving and returning to the page, a new session after a reload, the play time reported to trackers, plus realElapsed, formatDuration, and the migration and validation. Also checked in headless Chromium: opens paused at 0:00:00 with the hint, Start begins tracking and hides the hint, the setting persists and makes a reload start tracking, the long-gap prompt counts the gap.

Try by hand

  1. npm run dev: LSOS opens PAUSED with the "press Start once loaded in" hint. Press Start and watch session play time count up.
  2. Pause, wait, Start: the paused stretch isn't added.
  3. Settings → tick "Start tracking play time when LSOS opens", reload: it opens TRACKING from 0.
  4. Put the tab in the background for a few minutes and come back: that time is counted.
  5. Sleep the computer for more than 5 minutes while tracking: on waking, it asks whether you were playing.

🤖 Generated with Claude Code

Play time adds the gap between ticks, drops gaps over 5 minutes and is
saved in state version 2 (migrated from 1). Trackers ask for elapsed
play/real time with a TimeMark. Decision 008.

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Deploying lsos with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4dd93c6
Status: ✅  Deploy successful!
Preview URL: https://f646faac.lsos-2qs.pages.dev
Branch Preview URL: https://claude-2-clocks.lsos-2qs.pages.dev

View logs

… discards the tab

Gaps over 5 minutes are no longer dropped silently: they are held and the
user is asked whether they were playing. The last tick is saved, so a
discarded and reloaded tab continues; a normal close still stops the
clock. Ticks and saves on visibilitychange and freeze, and saveNow writes
the current state directly. Decision 008 updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Play time now lasts one session and is not saved; trackers will get each
counted stretch through onPlayTime and keep their own progress. LSOS opens
paused; a Settings checkbox starts tracking on open instead. The saved
clock section holds only that setting. Decisions 003 and 008 updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ToothyDev
ToothyDev merged commit 36a7885 into main Oct 14, 2026
4 checks passed
@ToothyDev
ToothyDev deleted the claude/2-clocks branch October 14, 2026 15:42
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.

Core: play-time and real-time clocks

2 participants