refactor(sound): extract playActionSound from FileViewer into src/sound.ts - #28
Merged
Conversation
…nd.ts FileViewer.tsx had a ~105-line inline Web Audio synthesis function (oscillator/gain/filter setup for the delete "whoosh" and keep "chime" sounds), untestable in jsdom and creating a brand-new AudioContext on every call. Move it to src/sound.ts, unchanged in what it plays: - playActionSound(action): void — no enabled parameter; FileViewer keeps the settings.soundEffects check itself, since it owns "when to play" - a lazily-created, module-level singleton AudioContext, reused across calls instead of created fresh each time - if construction fails once, that's cached so later calls skip retrying and re-logging (an environment-support gap, not transient) — scoped only to construction, not to a synthesis-time failure Also promotes the "delete" | "keep" union (independently duplicated across sound.ts, types.ts, FileViewer.tsx, and App.tsx) to one exported FileAction type in types.ts, per code review. Adds src/sound.test.ts: smoke-level coverage (constructs on delete/keep, reuses the same context across calls, doesn't throw when AudioContext is unavailable) — no assertions on exact frequencies/envelopes, since those are aesthetic choices, not correctness-critical. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FileViewer.tsxhad a ~105-line inline Web Audio synthesis function (oscillator/gain/filter setup for the delete "whoosh" and keep "chime" sounds), untestable in jsdom and creating a brand-newAudioContexton every call.src/sound.ts, unchanged in what it plays:playActionSound(action): void— no enabled parameter;FileViewerkeeps thesettings.soundEffectscheck itself, since it owns "when to play"AudioContext, reused across calls instead of created fresh each time"delete" | "keep"union (independently duplicated acrosssound.ts,types.ts,FileViewer.tsx, andApp.tsx) to one exportedFileActiontype intypes.ts, per code review.Test plan
npm run typecheckpasses (all 3 configs)npm test— 54/54 pass (4 new:sound.test.tscovers constructing on delete/keep, reusing the same context across calls, and not throwing whenAudioContextis unavailable — no assertions on exact frequencies/envelopes, since those are aesthetic, not correctness-critical)npm run build— Vite + Electron compile cleanlynpx biome checkclean on changed files"delete" | "keep"literal) fixed pre-commit🤖 Generated with Claude Code