Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

macOS: Beep When Done plays the system alert sound (NSBeep) instead of a terminal bell (#6537)

Marco Arnulfob4e0d2491dfe
diff --git a/apps/photocraft/Cargo.toml b/apps/photocraft/Cargo.toml
index e5af66347..cb8fe0ef5 100644
--- a/apps/photocraft/Cargo.toml
+++ b/apps/photocraft/Cargo.toml
@@ -50,11 +50,12 @@ core-graphics2 = { version = "=0.6.1", default-features = false, features = ["di
# safe API. Pinned exactly: review the diff before bumping.
fmv-macos-events = "=0.1.0"
# Safe AppKit calls only: turn off AppKit's title bar dragging (mac_window.rs) and find where the
-# pointer is when files are dropped (cursor.rs; winit 0.30 drops carry no position). Already in
+# pointer is when files are dropped (cursor.rs; winit 0.30 drops carry no position), and play the
+# system alert sound for Beep When Done (services.rs, NSBeep). Already in
# Cargo.lock (winit, photocraft-tablet); pinned exactly to the same versions.
objc2 = "=0.6.4"
objc2-foundation = { version = "=0.3.2", default-features = false, features = ["std", "NSArray", "NSEnumerator", "NSGeometry"] }
-objc2-app-kit = { version = "=0.3.2", default-features = false, features = ["std", "NSApplication", "NSApplicationScripting", "NSEvent", "NSResponder", "NSView", "NSWindow"] }
+objc2-app-kit = { version = "=0.3.2", default-features = false, features = ["std", "NSApplication", "NSApplicationScripting", "NSEvent", "NSGraphics", "NSResponder", "NSView", "NSWindow"] }
# The macOS menu bar (mac_menu.rs): a standalone native menu crate (from the tauri-apps org, but
# not Tauri: no webview, no JS), AppKit menus behind a safe API (no GTK with default features off). Pinned exactly: review the diff before bumping.
muda = { version = "=0.21.1", default-features = false }
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs
index 6c34fda33..e0ab1c527 100644
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@ -574,10 +574,14 @@ fn platform_beep() {
{
let _ = winsafe::MessageBeep(winsafe::co::MBP::OK);
}
- #[cfg(not(target_os = "windows"))]
+ // The user's alert sound, at the alert volume set in System Settings ▸ Sound. The terminal
+ // bell below is silent for an app started from the Finder or the Dock.
+ #[cfg(target_os = "macos")]
+ objc2_app_kit::NSBeep();
+ #[cfg(not(any(target_os = "windows", target_os = "macos")))]
{
- // No beep API among this app's other platforms' dependencies: write the terminal bell
- // (audible when launched from a terminal, which is the same cue macOS terminals use).
+ // No beep API among the other platforms' dependencies: write the terminal bell (audible
+ // when launched from a terminal).
use std::io::Write as _;
let _ = std::io::stdout().write_all(b"\x07").and_then(|()| std::io::stdout().flush());
}