diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-09 13:48:06 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-09 13:48:06 -0500 |
| commit | e022368a8d640aca9e5700249d70bacf948cfa7a (patch) | |
| tree | 3775db77089394f8b01e38b299a834ebf133d181 /tests/test-chime-notify.el | |
| parent | cccc205f0163395366f54f83011a161bfce3129c (diff) | |
| download | chime-e022368a8d640aca9e5700249d70bacf948cfa7a.tar.gz chime-e022368a8d640aca9e5700249d70bacf948cfa7a.zip | |
fix: play the chime through an external player when one is available
Emacs' play-sound-file opens an ALSA device directly, so it fails with "No usable sound device driver found" wherever ALSA's default PCM doesn't resolve. That's every PipeWire system where nothing points pcm.!default at the sound server. It also blocks Emacs until the clip finishes, and on macOS it isn't compiled in at all.
chime now hands the file to the first of pw-play, paplay, afplay or aplay found on exec-path, spawned asynchronously. I put aplay last because it speaks raw ALSA and shares play-sound-file's failure mode, so falling back to it from a broken default PCM would buy nothing. With no external player installed, play-sound-file still runs, now taking chime-sound-device as its DEVICE argument.
Two new defcustoms: chime-sound-player (auto, emacs, or a command name) and chime-sound-device. Both default to today's behavior for anyone whose sound already works.
A player that spawns and then exits non-zero is reported through a process sentinel rather than failing silently. The sentinel doesn't fall back to play-sound-file, which would reintroduce the blocking ALSA call this change avoids.
I pinned the notify tests to emacs so they mock one function and never spawn a real player.
Diffstat (limited to 'tests/test-chime-notify.el')
| -rw-r--r-- | tests/test-chime-notify.el | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/test-chime-notify.el b/tests/test-chime-notify.el index 0b77993..822bf00 100644 --- a/tests/test-chime-notify.el +++ b/tests/test-chime-notify.el @@ -36,7 +36,12 @@ (setq chime-notification-icon nil) (setq chime-extra-alert-plist nil) ;; Use a simple test path for sound file - (setq chime-sound-file "/tmp/test-chime.wav")) + (setq chime-sound-file "/tmp/test-chime.wav") + ;; Route sound through `play-sound-file' so these tests mock one function + ;; and never spawn a real external player. The player-selection contract + ;; itself is covered in test-chime-sound.el. + (setq chime-sound-player 'emacs) + (setq chime-sound-device nil)) (defun test-chime-notify-teardown () "Teardown function run after each test." @@ -57,7 +62,7 @@ ((symbol-function 'file-exists-p) (lambda (file) t)) ;; Mock play-sound-file to track if called ((symbol-function 'play-sound-file) - (lambda (file) + (lambda (&rest _) (setq sound-played t))) ;; Mock alert to track if called ((symbol-function 'alert) @@ -146,7 +151,7 @@ ;; Mock file-exists-p to return nil ((symbol-function 'file-exists-p) (lambda (file) nil)) ((symbol-function 'play-sound-file) - (lambda (file) (setq sound-played t))) + (lambda (&rest _) (setq sound-played t))) ((symbol-function 'alert) (lambda (msg &rest args) (setq alert-called t)))) (chime--notify "Test Event") @@ -169,7 +174,7 @@ ((symbol-function 'file-exists-p) (lambda (file) t)) ;; Mock play-sound-file to throw error ((symbol-function 'play-sound-file) - (lambda (file) (error "Sound playback failed"))) + (lambda (&rest _) (error "Sound playback failed"))) ((symbol-function 'alert) (lambda (msg &rest args) (setq alert-called t)))) ;; Should not throw error |
