@@ -56,56 +56,10 @@ def __init__(self, config_manager=None):
5656 if not self .assets_dir .exists ():
5757 self .assets_dir = Path (__file__ ).parent .parent / "assets"
5858
59- # Start sound path resolution
60- if self .start_sound_path :
61- # Try the path as-is first (for absolute paths)
62- start_path = Path (self .start_sound_path )
63- if start_path .exists ():
64- self .start_sound = start_path
65- else :
66- # Try relative to assets directory (for relative paths like "ping-up.ogg")
67- start_path = self .assets_dir / self .start_sound_path
68- if start_path .exists ():
69- self .start_sound = start_path
70- else :
71- # Fall back to default
72- self .start_sound = self .assets_dir / "ping-up.ogg"
73- else :
74- self .start_sound = self .assets_dir / "ping-up.ogg"
75-
76- # Stop sound path resolution
77- if self .stop_sound_path :
78- # Try the path as-is first (for absolute paths)
79- stop_path = Path (self .stop_sound_path )
80- if stop_path .exists ():
81- self .stop_sound = stop_path
82- else :
83- # Try relative to assets directory (for relative paths like "ping-down.ogg")
84- stop_path = self .assets_dir / self .stop_sound_path
85- if stop_path .exists ():
86- self .stop_sound = stop_path
87- else :
88- # Fall back to default
89- self .stop_sound = self .assets_dir / "ping-down.ogg"
90- else :
91- self .stop_sound = self .assets_dir / "ping-down.ogg"
92-
93- # Error sound path resolution
94- if self .error_sound_path :
95- # Try the path as-is first (for absolute paths)
96- error_path = Path (self .error_sound_path )
97- if error_path .exists ():
98- self .error_sound = error_path
99- else :
100- # Try relative to assets directory (for relative paths like "ping-error.ogg")
101- error_path = self .assets_dir / self .error_sound_path
102- if error_path .exists ():
103- self .error_sound = error_path
104- else :
105- # Fall back to default
106- self .error_sound = self .assets_dir / "ping-error.ogg"
107- else :
108- self .error_sound = self .assets_dir / "ping-error.ogg"
59+ # Resolve sound paths (custom path -> relative to assets -> default)
60+ self .start_sound = self ._resolve_sound_path (self .start_sound_path , "ping-up.ogg" )
61+ self .stop_sound = self ._resolve_sound_path (self .stop_sound_path , "ping-down.ogg" )
62+ self .error_sound = self ._resolve_sound_path (self .error_sound_path , "ping-error.ogg" )
10963
11064 # Check if audio files exist
11165 self .start_sound_available = self .start_sound .exists ()
@@ -127,11 +81,29 @@ def _validate_volume(self, volume: float) -> float:
12781 volume = float (volume )
12882 except (ValueError , TypeError ):
12983 volume = 0.3
130-
84+
13185 # Clamp between 0.1 (10%) and 1.0 (100%)
13286 volume = max (0.1 , min (volume , 1.0 ))
13387 return volume
134-
88+
89+ def _resolve_sound_path (self , custom_path : Optional [str ], default_filename : str ) -> Path :
90+ """
91+ Resolve a sound file path with fallback logic.
92+
93+ Tries: custom_path as-is -> custom_path relative to assets -> default
94+ """
95+ if custom_path :
96+ # Try as absolute path first
97+ path = Path (custom_path )
98+ if path .exists ():
99+ return path
100+ # Try relative to assets directory
101+ path = self .assets_dir / custom_path
102+ if path .exists ():
103+ return path
104+ # Fall back to default
105+ return self .assets_dir / default_filename
106+
135107 def _play_sound (self , sound_file : Path , volume : float = None ) -> bool :
136108 """
137109 Play an audio file with volume control
0 commit comments