From 3de16cc74c835dbdb455fffa66d7bb955cfc6c83 Mon Sep 17 00:00:00 2001 From: macworkers Date: Mon, 4 May 2026 15:57:04 -0700 Subject: [PATCH] fix(notifications): actually call MessageBeep on Windows (#602) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented using `deepseek exec --model deepseek-v4-flash`. 🐋 --- crates/tui/Cargo.toml | 2 +- crates/tui/src/tui/notifications.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/tui/Cargo.toml b/crates/tui/Cargo.toml index 518be328..35d83f1e 100644 --- a/crates/tui/Cargo.toml +++ b/crates/tui/Cargo.toml @@ -80,4 +80,4 @@ libc = "0.2" libc = "0.2" [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "0.60", features = ["Win32_Foundation"] } +windows = { version = "0.60", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging"] } diff --git a/crates/tui/src/tui/notifications.rs b/crates/tui/src/tui/notifications.rs index d42df7e8..2af7f960 100644 --- a/crates/tui/src/tui/notifications.rs +++ b/crates/tui/src/tui/notifications.rs @@ -5,6 +5,9 @@ //! tmux DCS passthrough so OSC 9 reaches the outer terminal even when //! running inside a tmux session. +#[cfg(target_os = "windows")] +use windows::Win32::UI::WindowsAndMessaging::MessageBeep; + use std::io::{self, Write}; use std::time::Duration; @@ -36,6 +39,19 @@ impl Method { } } +/// Emit a Windows system beep via `MessageBeep(MB_OK)`. +/// +/// Writing BEL (`\\x07`) to the terminal is silent on most Windows +/// terminals (Windows Terminal, Conhost, etc.), so we call the Win32 +/// API directly to produce the standard notification sound. +#[cfg(target_os = "windows")] +fn windows_bell() { + // MB_OK = 0x00000000 — plays the default system sound. + unsafe { + MessageBeep(0x00000000); + } +} + /// Resolve `Auto` to a concrete method by inspecting `$TERM_PROGRAM`. /// /// Known OSC-9 capable programs: `iTerm.app`, `Ghostty`, `WezTerm`. @@ -101,6 +117,14 @@ pub fn notify_done_to( // Best-effort: ignore write errors (e.g. stdout closed). let _ = sink.write_all(&bytes); let _ = sink.flush(); + + // On Windows, writing BEL (`\x07`) to the terminal is silent in most + // terminals (Windows Terminal, Conhost, etc.). Call MessageBeep to + // produce an actual notification sound via the system audio scheme. + #[cfg(target_os = "windows")] + if effective == Method::Bel { + windows_bell(); + } } /// Emit a turn-complete notification to **stdout** if `elapsed >= threshold`.