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
5.9 KiB
AGENTS.md
Guidance for AI coding agents working in this repository. Human contributors: see CONTRIBUTING.md.
What this is
HushKey is a Rust tray app that binds global keyboard shortcuts to mute/unmute individual applications' audio, plus a Mute All shortcut. One codebase for Windows, macOS and Linux. The UI is Slint with the software renderer. Do not introduce a webview (Tauri, wry, Electron) or a GPU renderer: low idle memory is a core product requirement.
Project structure
src/
main.rs CLI flags, single-instance guard, Slint backend selection, event loop
app.rs main-thread controller (config, hotkeys, tray, toast, window lifecycle)
platform.rs launch-at-login, open-folder, single-instance socket
audio/
mod.rs AudioController trait, AudioApp/AppKey/AudioError, create_controller()
mute.rs MuteManager: toggle / mute-all / restore-all semantics ← unit tests
worker.rs audio thread; AudioCommand in, AudioEvent out
windows.rs Windows backend: WASAPI IAudioSessionManager2 / ISimpleAudioVolume
macos.rs macOS backend: Core Audio process taps (14.2+), mute-only
linux.rs Linux backend: libpulse sink inputs (works on PipeWire)
null.rs in-memory backend for tests / unsupported OSes
hotkeys/
accelerator.rs Accelerator type, "Ctrl+Alt+S" format, Slint key → shortcut ← unit tests
mod.rs Hotkeys: register config bindings, suspend during capture
config/mod.rs Config + ConfigStore (TOML, atomic writes) ← unit tests
ui/
mod.rs helpers (avatar tint, initials, icon conversion)
icon.rs procedural app/tray icon rasteriser ← unit tests
tray.rs tray icon + menu
toast.rs non-activating on-screen confirmation window
ui/ .slint files (main.slint, widgets.slint, theme.slint, toast.slint)
build.rs compiles ui/main.slint (fluent style)
docs/ architecture.md, building.md, design-decisions.md
Build / run / test
| Task | Command |
|---|---|
| Build (debug) | cargo build |
| Run | cargo run (window opens) · cargo run -- --minimized (tray only) |
| List detected audio apps | cargo run -- --list |
| Unit tests | cargo test |
| Lint | cargo clippy --all-targets -- -D warnings |
| Format | cargo fmt |
| Release | cargo build --release (fat LTO; slow, a few minutes) |
| Type-check macOS from anywhere | rustup target add aarch64-apple-darwin && cargo check --target aarch64-apple-darwin |
Per-OS system dependencies are in docs/building.md. On Linux you need libpulse-dev, libfontconfig1-dev, libxkbcommon-dev and pkg-config.
Tests don't touch real audio devices: they use audio::null::NullController. Backend code can only be verified by running the app on that OS. Say clearly which OS you actually ran on.
Conventions
- Platform code stays in
src/audio/<os>.rs(and smallcfgblocks inplatform.rs,ui/toast.rs,main.rs). Everything else must compile and behave identically on all OSes. - New capabilities go through the
AudioControllertrait. Never call an OS audio API fromapp.rsor the UI. - Backends are created on the audio thread and are not
Send. Don't move them across threads or put them inArc<Mutex<..>>. - Never fake a capability. If an OS can't do something (macOS volume levels), return
AudioError::Unsupported, setCapabilitiesaccordingly, and explain it in the module doc comment,platform_note(), anddocs/design-decisions.md. - Mute with the mixer's mute flag, not by setting volume to 0 (crash-safety; see design-decisions).
- Errors:
AudioResult<T>in audio code; user-facing strings go throughApp::set_statusor the toast. Nounwrap()on OS calls. - UI strings live in
.slintfiles; keep them short, sentence case. - Slint gotcha:
row,col,x,y,width,heightare built-in properties. Don't name custom properties after them. - Formatting:
rustfmt.toml(max width 120). Runcargo fmtbefore finishing. - Commit messages: Conventional Commits (
feat(audio): …,fix(ui): …).
Gotchas
- Hotkeys must be registered on the main thread (Windows: the message-loop thread; macOS: requires the main run loop).
Hotkeysis created inApp::start. - While recording a shortcut, all hotkeys are unregistered (
Hotkeys::suspend). Forgetting to callend_captureleaves the user with no working shortcuts. - The tray must be created after the event loop starts (macOS requirement). It's done in a zero-delay
slint::Timer. - The toast must never take focus. It relies on
ui::toast::window_attributes_hookand the thread-localNEXT_WINDOW_IS_TOASTflag set immediately beforeToast::new(). Any new window type created between those calls would inherit the toast attributes. - The main window is dropped on close (
App::release_window). Never hold a strongMainWindowhandle in a closure. Usewith_app(|a| ...)from callbacks. - Windows COM:
WasapiControllerinitialises COM (MTA) on the audio thread and uninitialises inComGuard, which must remain the last struct field. - macOS: tap functions are resolved with
dlsym. Don't link them directly or the app won't launch on macOS < 14.2. Muting requires the Screen & System Audio Recording permission plusNSAudioCaptureUsageDescriptionin the bundle's Info.plist. - Linux: global hotkeys are X11-only. Under Wayland they appear to register but don't fire for native Wayland windows.
- Permissions summary: Windows needs none. macOS needs audio-capture permission for muting (no Accessibility permission for hotkeys). Linux needs an X11 session for hotkeys and a StatusNotifierItem host for the tray.
- The single-instance guard binds
127.0.0.1:47219. A second launch asks the first to show its window and exits.