fix(sound): iOS timer sounds — resume before every tone, unlock from the tap, and a "play on silent" setting (#152)

Three things iOS needs that a desktop browser does not, all in lib/sound.js:

1. The ring/silent switch mutes Web Audio: a page whose only audio is Web Audio gets the
   Ambient category, which obeys the switch. The way out is the 'playback' audio-session type
   (iOS 17+), which is exclusive — it pauses whatever else is playing and WebKit never tells that
   app it may resume — so it is a setting, off by default: Settings → Sounds → "Play sounds when
   the phone is on silent" (S.soundOnSilent, applied page-wide by App.jsx). Offered only where it
   means something: a WebKit with navigator.audioSession on a device with a switch.
2. Locking the screen or switching apps leaves a suspended context suspended, and a suspended
   context makes no sound: every tone resumes the context first. The context sleeps again a
   second after the last tone so it does not keep the phone's audio session busy.
3. A context created outside a tap starts suspended and no timer tick can start it: unlock()
   runs from the taps that lead to a timer (turning Sounds on, starting a hold).

Split out of #165 at the maintainer's request; the per-kind rest-over sounds and the timer-bar
work stay there. Tests: lib/sound.test.js (fake AudioContext + audioSession), views/Settings.sound.test.jsx.
This commit is contained in:
Boris Kurktchiev committed 2026-09-12 16:13:17 -04:00
1 parent 14c454f5c1
commit 6e44e2f793
23 files changed
+459 -9

No files matched your search

+4
View File
@@ -5,6 +5,7 @@ import { useUI } from './store/useUI.js'
import { bindUI } from './components/ui.jsx'
import { ACCENTS } from './lib/format.js'
import { setLang, useLang } from './lib/i18n.js'
import { setPlayOnSilent } from './lib/sound.js'
import { setNav } from './lib/nav.js'
import { initBackButton } from './lib/back.js'
import { useWakeLock } from './lib/wakelock.js'
@@ -61,6 +62,9 @@ function Shell() {
const loc = useLocation()
const navType = useNavigationType()
const { S, user, ready } = useStore()
// iOS: whether timer sounds get past the ring/silent switch (Settings → Sounds). Page-level,
// so it is applied here on load and on change rather than at each beep.
useEffect(() => { setPlayOnSilent(!!S.soundOnSilent) }, [S.soundOnSilent])
const isGuest = useStore(s => s.isGuest())
const needsMobileOnboarding = useStore(s => s.needsMobileOnboarding)
const langV = useLang() // re-renders the whole shell when the language (pack) changes