Skip to content

refactor(sound): extract playActionSound from FileViewer into src/sound.ts - #28

Merged
killerwolf merged 1 commit into
mainfrom
claude/extract-sound-module
Sep 2, 2026
Merged

refactor(sound): extract playActionSound from FileViewer into src/sound.ts#28
killerwolf merged 1 commit into
mainfrom
claude/extract-sound-module

Conversation

@killerwolf

Copy link
Copy Markdown
Owner

Summary

  • 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
  • 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.

Test plan

  • npm run typecheck passes (all 3 configs)
  • npm test — 54/54 pass (4 new: sound.test.ts covers constructing on delete/keep, reusing the same context across calls, and not throwing when AudioContext is unavailable — no assertions on exact frequencies/envelopes, since those are aesthetic, not correctness-critical)
  • npm run build — Vite + Electron compile cleanly
  • npx biome check clean on changed files
  • Reviewed against CONTRIBUTING.md standards and the original design (two-axis review); Spec review clean (numeric values verified byte-for-byte identical to the original), one Standards finding (duplicated "delete" | "keep" literal) fixed pre-commit

🤖 Generated with Claude Code

…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>
@killerwolf
killerwolf merged commit 4ecab7b into main Sep 2, 2026
2 checks passed
@killerwolf
killerwolf deleted the claude/extract-sound-module branch September 2, 2026 18:18
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.

1 participant