Skip to content

[bug] No notification sound on Windows #6652

@Lej77

Description

@Lej77

Describe the bug

Notifications on Windows don't make any sound when shown. This is not the default and most other apps do make a sound when showing a notification.

Reproduction

  1. Show a notification on windows:
use tauri::api::notification::Notification;

Notification::new(&app.config().tauri.bundle.identifier)
    .title("New message")
    .body("You've got a new message.")
    .notify(app)
    .expect("failed to show notification");

Expected behavior

A notification is shown and a sound is played.

Platform and versions

Environment
  › OS: Windows 10.0.19044 X64
  › Webview2: 111.0.1661.62
  › MSVC: 
      - Visual Studio Community 2022
  › Node.js: 19.7.0
  › npm: 9.5.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.25.2
  › rustc: 1.68.2
  › cargo: 1.68.2
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages
WARNING: no lock files found, defaulting to npm
  › @tauri-apps/cli [NPM]: 1.2.3
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: 1.2.4,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:1420/
package.json not found

App directory structure
  ├─ .git
  ├─ .vscode
  ├─ dist
  ├─ public
  ├─ src
  └─ src-tauri

Stack trace

No response

Additional context

tauri-apps/plugins-workspace#2144 might be relevant to this issue.

Tauri uses the notify-rust crate to handle notifications (source). Its notify_rust::Notification::sound_name method allows specifying the sound name. The sound name is later in its windows implementation parsed using winrt_notification::Sound::from_str which is derive using
strum::EnumString. The derive macro's documentation says "Each variant of the enum will match on it’s own name". Which means we need to pass the string "Default" to get the default sound. Finally this enum is converted to the real audio tag in winrt_notification::Toast::sound.

Note that setting the sound to None results in <audio silent=\"true\" /> being appended to the "toast" xml in the winrt-notification crate while specifying the Default sound appends an empty string.

Anyway, this all means that the issue can be solved by adding the following code:

#[cfg(windows)]
{
    notification.sound_name("Default");
}

In the tauri::api::notification::Notification::show method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions