fix: unlock audio context on first user interaction
UI sounds weren't playing until the user hit Play because Tone.js AudioContext was suspended. Now Tone.start() is called on the first pointerdown or keydown event, so UI sounds work immediately. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
12
src/main.jsx
12
src/main.jsx
@@ -16,6 +16,18 @@ function Root() {
|
||||
|
||||
createRoot(document.getElementById('root')).render(<Root />);
|
||||
|
||||
// Unlock audio context on first user interaction
|
||||
import * as Tone from 'tone';
|
||||
const unlockAudio = () => {
|
||||
if (Tone.context.state !== 'running') {
|
||||
Tone.start().catch(() => {});
|
||||
}
|
||||
document.removeEventListener('pointerdown', unlockAudio);
|
||||
document.removeEventListener('keydown', unlockAudio);
|
||||
};
|
||||
document.addEventListener('pointerdown', unlockAudio);
|
||||
document.addEventListener('keydown', unlockAudio);
|
||||
|
||||
// Register service worker for PWA
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
|
||||
Reference in New Issue
Block a user