Native Rust tray app that binds global shortcuts to mute/unmute individual applications' audio, plus a Mute All / Restore All shortcut. - AudioController trait with per-OS backends: WASAPI sessions (Windows), Core Audio process taps (macOS 14.2+, mute only), PulseAudio/PipeWire sink inputs (Linux) - Dedicated audio thread; hotkey presses go straight to it - Snapshot-based Mute All that restores exactly the previous state - Slint UI with software renderer; window destroyed on close - Non-activating on-screen confirmation and tray icon flash - TOML config, launch at login, start minimized, dark/light theme - Procedurally drawn icon embedded into the Windows executable - Docs, AGENTS.md, CLAUDE.md, contributing guide and CI for all three OSes
3.6 KiB
3.6 KiB
CLAUDE.md
This file guides Claude Code when working in this repository. The full agent guide is AGENTS.md; read it first. This file covers the essentials and what needs extra care.
Project overview
HushKey: a native Rust tray app (Windows/macOS/Linux) that binds global shortcuts to mute/unmute individual apps' audio, plus a Mute All shortcut. UI is Slint with the software renderer; minimal idle memory is a hard requirement. No webviews (Tauri/wry), no GPU renderers.
Key commands
cargo build # debug build
cargo run # run with window; `-- --minimized` for tray only
cargo run -- --list # print detected audio apps (real devices)
cargo test # unit tests (no audio hardware needed)
cargo clippy --all-targets -- -D warnings # lint
cargo fmt # format (rustfmt.toml, width 120)
cargo check --target aarch64-apple-darwin # type-check the macOS backend from Windows/Linux
Architecture pointers
src/audio/mod.rs: theAudioControllertrait. All OS audio code is behind it.src/audio/{windows,macos,linux}.rs: one backend per OS.null.rsis the test double.src/audio/mute.rs: toggle / Mute All / Restore All rules (snapshot-based restore).src/audio/worker.rs: the audio thread. Hotkey presses are sent here directly, bypassing the UI.src/app.rs: main-thread controller.with_app(|a| ...)is how callbacks reach it.ui/*.slint: the UI.build.rscompilesui/main.slint.- Docs:
docs/architecture.md,docs/design-decisions.md(platform limitations),docs/building.md.
Be careful when editing audio backend code
- Keep platform code inside
src/audio/<os>.rs. Don't call OS audio APIs fromapp.rs/UI; extend the trait instead. - Backends live on the audio thread and are
!Sendby design (COM apartment, PulseAudio mainloop, Core Audio taps). Don't wrap them inArc<Mutex<_>>or move them. - Mute via the mixer mute flag, never by setting volume to 0. This keeps the user's level and is crash-safe.
- Group by
AppKey, never by PID. Bindings must survive restarts; one key controls all of an app's sessions. - Never fake unsupported features. macOS can't set per-app volume: return
AudioError::Unsupported, keepCapabilitieshonest, and document it. - Windows:
ComGuardmust stay the last field ofWasapiController(field drop order = COM release beforeCoUninitialize). Enumerate sessions on all active render devices, not just the default. - macOS: resolve
AudioHardwareCreateProcessTap/DestroyProcessTapviadlsym. Linking them directly breaks launch on macOS < 14.2. Taps must be destroyed inDrop. - Linux: every PulseAudio operation must be driven to completion with
wait()on the same thread. - You can only truly verify a backend by running
cargo run -- --listand muting on that OS. State plainly which OS you tested on; macOS and Linux changes made from Windows are compile-checked at best. - Don't send synthetic keyboard/mouse input to test the UI on a developer's live desktop. Ask them to try it instead.
Other gotchas
- Shortcut recording calls
Hotkeys::suspend(). Every exit path must reachApp::end_capture()so hotkeys are re-registered. - The toast window depends on the
NEXT_WINDOW_IS_TOASTflag consumed by the winit attributes hook insrc/ui/toast.rs. Keep it non-activating so it never steals focus from games. - Slint reserves property names like
row,col,x,y. Pick other names.