Let sleep tracking be switched off

Settings gets a Track sleep switch, stored on the synced profile as
sleepOff (negative, so a profile from before it, or an old client that
doesn't send it, means tracking). Off hides everything marked
data-sleep-only (the sleep log buttons, the Sleep tab, the Sleep/Awake
tiles, Last sleep and the Sleep & wake list) plus the bar timer. The
sleep state also reads as unknown, so a leftover sleep-start can't dim
the log buttons or run a sleep rail through every day's history.

The reminder scheduler treats the state as unknown too. Otherwise a
leftover sleep-start would mute every other rule for good, or a leftover
sleep-end would fire the sleep rule every interval. Nothing logged is
deleted.
This commit is contained in:
Alexander Heldt committed 2026-11-12 10:27:03 +00:00
1 parent f98137097c
commit a01d74e9d5
7 files changed
+176 -32

No files matched your search

+16 -1
View File
@@ -188,10 +188,25 @@ type sleepState struct {
since int64 // ms epoch of that boundary
}
// sleepStateFor reads that boundary for one user. An account that has switched
// sleep tracking off has no sleep state at all,
// whatever boundaries are left in its log. Reading the last one anyway would
// leave the puppy "asleep" from the day tracking stopped, with every other
// rule silenced for good — or "awake" since then, with the sleep rule firing
// every interval forever.
func (sch *Scheduler) sleepStateFor(userID string) (sleepState, error) {
var off bool
err := sch.db.QueryRow(`SELECT sleep_off FROM config WHERE user_id = ?`, userID).Scan(&off)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return sleepState{}, err
}
if off {
return sleepState{}, nil
}
var typ string
var at int64
err := sch.db.QueryRow(`
err = sch.db.QueryRow(`
SELECT type, at FROM events
WHERE user_id = ? AND deleted = 0 AND type IN ('sleep-start', 'sleep-end')
ORDER BY at DESC, updated DESC LIMIT 1`, userID).Scan(&typ, &at)