Skip to content

Windows: a notification sound file of the user's own - #150

Open
JosueMeserom wants to merge 1 commit into
karem505:masterfrom
JosueMeserom:custom-notification-sound
Open

JosueMeserom wants to merge 1 commit into
karem505:masterfrom
JosueMeserom:custom-notification-sound

Conversation

@JosueMeserom

Copy link
Copy Markdown

What

Settings › Notifications gets an Alert sound row (Windows only): pick a WAV, MP3, M4A/AAC, WMA, FLAC or OGG file and whatRust plays it for message notifications instead of Windows' toast sound. Reset to default goes back to Windows' sound. Nothing changes until a file is chosen.

Why

An app without package identity can only name one of Windows' own ms-winsoundevent: sounds in its toast XML, not a file, so there was no way to get, for example, the sound of the official WhatsApp app.

How

  • With a file chosen, the toast goes out silent and sound.rs plays the file with WinRT's MediaPlayer, on a thread of its own, in whatRust's own audio session (so the volume mixer controls it with the app). Its command manager is disabled, so it adds no entry to Windows' media controls.
  • A new sound cuts off the one still playing, so a burst of messages does not pile up sounds.
  • The Notification sound switch still rules: with it off, nothing plays.
  • A file that has gone away falls back to Windows' sound. The picker and set_settings only accept existing files with one of the extensions above.
  • Like the download folder, the file is machine-specific: restoring a backup keeps this computer's choice.
  • New command pick_notification_sound: listed in build.rs, granted in capabilities/settings.json (Settings window only, not main-remote) and added to ipc_acl_tests.rs. It plays the chosen file once so it can be heard.
  • Strings in i18n.rs and settings-ui/i18n.js (English, Spanish, Arabic, Indonesian).
  • Only two features of the windows crate are added (Media_Core, Media_Playback); no new crates, so flatpak/cargo-sources.json does not change.
  • Tests for sound::usable and sound::custom.

Testing

  • Windows 11 (build 26300): built with cargo build --release and in daily use with the notification sound of WhatsApp's Store app (an .m4a). The toast is silent, the file plays, and the picker works.
  • cargo fmt --check, cargo clippy --locked -- -D warnings and cargo test --locked pass on Windows; the JavaScript tests from CONTRIBUTING.md pass.
  • Not tried on Linux or macOS. The row is hidden there and sound::play is a no-op; sound::custom and its test are behind #[cfg(windows)] so clippy has no dead code there, but I could not run clippy on those systems.

🤖 Generated with Claude Code

Settings > Notifications gets "Alert sound" (Windows only): a WAV, MP3, M4A,
WMA, FLAC or OGG file played instead of Windows' toast sound. An unpackaged
app's toast can only name Windows' own sounds, so with a file chosen the
toast goes silent and whatRust plays the file with MediaPlayer, in its own
audio session and without an entry in Windows' media controls. A new sound
cuts off the one still playing. A file that has gone away falls back to
Windows' sound; a backup keeps this computer's file, as it does the
download folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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