Fix volume spam: deduplicate set_volume calls in backend
- Skip setting volume if already at same value (0.001 tolerance) - Skip logging when volume unchanged - Prevents MPRIS/PipeWire feedback loop spam
This commit is contained in:
1 parent
43444951ba
commit
5a93ac509d
2 files changed
+12
-1
No files matched your search
@@ -828,7 +828,11 @@ pub fn set_media_metadata(
|
||||
/// Set volume (0.0 - 1.0)
|
||||
#[tauri::command]
|
||||
pub fn set_volume(volume: f32, state: State<'_, AppState>) -> Result<(), String> {
|
||||
log::info!("Command: set_volume {}", volume);
|
||||
// Skip logging if volume is the same (reduces log spam from MPRIS polling)
|
||||
let current = state.player.state.volume();
|
||||
if (volume - current).abs() >= 0.001 {
|
||||
log::info!("Command: set_volume {}", volume);
|
||||
}
|
||||
state.player.set_volume(volume)
|
||||
}
|
||||
|
||||
|
||||
@@ -1909,6 +1909,13 @@ impl Player {
|
||||
/// Set volume (0.0 - 1.0)
|
||||
pub fn set_volume(&self, volume: f32) -> Result<(), String> {
|
||||
let clamped = volume.clamp(0.0, 1.0);
|
||||
|
||||
// Skip if volume is already at this value (prevents MPRIS/PipeWire feedback loop)
|
||||
let current = self.state.volume();
|
||||
if (clamped - current).abs() < 0.001 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.tx
|
||||
.send(AudioCommand::SetVolume(clamped))
|
||||
.map_err(|e| format!("Failed to send volume command: {}", e))
|
||||
|
||||
Reference in new issue
Block a user