From 3cbe529b7a637d89b90a2ab6efd2cbaceadec1e8 Mon Sep 17 00:00:00 2001 From: cottongin Date: Tue, 10 Mar 2026 02:44:45 -0400 Subject: [PATCH] feat: add system sound alert module Made-with: Cursor --- src/cursor_flasher/sound.py | 17 +++++++++++++++++ tests/test_sound.py | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/cursor_flasher/sound.py create mode 100644 tests/test_sound.py diff --git a/src/cursor_flasher/sound.py b/src/cursor_flasher/sound.py new file mode 100644 index 0000000..f96a3e6 --- /dev/null +++ b/src/cursor_flasher/sound.py @@ -0,0 +1,17 @@ +"""System sound playback.""" +from Cocoa import NSSound + +from cursor_flasher.config import Config + + +def play_alert(config: Config) -> None: + """Play the configured alert sound if enabled.""" + if not config.sound_enabled: + return + + sound = NSSound.soundNamed_(config.sound_name) + if sound is None: + return + + sound.setVolume_(config.sound_volume) + sound.play() diff --git a/tests/test_sound.py b/tests/test_sound.py new file mode 100644 index 0000000..8891744 --- /dev/null +++ b/tests/test_sound.py @@ -0,0 +1,20 @@ +import pytest +from unittest.mock import patch, MagicMock +from cursor_flasher.sound import play_alert +from cursor_flasher.config import Config + + +class TestPlayAlert: + def test_does_nothing_when_disabled(self): + config = Config(sound_enabled=False) + play_alert(config) + + @patch("cursor_flasher.sound.NSSound") + def test_plays_named_sound(self, mock_nssound): + mock_sound_obj = MagicMock() + mock_nssound.soundNamed_.return_value = mock_sound_obj + config = Config(sound_enabled=True, sound_name="Glass", sound_volume=0.7) + play_alert(config) + mock_nssound.soundNamed_.assert_called_once_with("Glass") + mock_sound_obj.setVolume_.assert_called_once_with(0.7) + mock_sound_obj.play.assert_called_once()