feat: add system sound alert module
Made-with: Cursor
This commit is contained in:
17
src/cursor_flasher/sound.py
Normal file
17
src/cursor_flasher/sound.py
Normal file
@@ -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()
|
||||||
20
tests/test_sound.py
Normal file
20
tests/test_sound.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user