From 2c044de38f6adcfbd3cc64eb9fa55e67d61e6f94 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 2 Nov 2026 13:22:44 +0100 Subject: config: parse the config once and reuse it until the file changes Every command, status line and notification went through Config::load, which reads *and* rewrites config.toml, so `rsp status` alone touched the file on each call. The daemon now keeps a parsed copy and only stats the file to notice outside edits, so `rsp settings set` still takes effect immediately. Config::save refreshes the cached copy too, and Config::config_path is shared by the loader and the cache. --- src/mpris.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/mpris.rs') diff --git a/src/mpris.rs b/src/mpris.rs index de19113..9daf516 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -204,7 +204,7 @@ impl MprisPlayer { if let Ok(mut s) = self.scrobble_state.lock() { s.start(track.clone()); } - let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); + let fmt = Config::cached().ok().and_then(|c| c.display_format.clone()); notification::notify_track(&track, fmt.as_deref()); } else { self.audio.stop(); @@ -226,7 +226,7 @@ impl MprisPlayer { if let Ok(mut s) = self.scrobble_state.lock() { s.start(track.clone()); } - let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); + let fmt = Config::cached().ok().and_then(|c| c.display_format.clone()); notification::notify_track(&track, fmt.as_deref()); } } @@ -271,7 +271,7 @@ impl MprisPlayer { if let Ok(mut s) = self.scrobble_state.lock() { s.start(track.clone()); } - let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); + let fmt = Config::cached().ok().and_then(|c| c.display_format.clone()); notification::notify_track(track, fmt.as_deref()); } } @@ -319,7 +319,7 @@ impl MprisPlayer { if let Ok(mut s) = self.scrobble_state.lock() { s.start(t.clone()); } - let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); + let fmt = Config::cached().ok().and_then(|c| c.display_format.clone()); notification::notify_track(t, fmt.as_deref()); } } else if path.is_file() { @@ -331,7 +331,7 @@ impl MprisPlayer { if let Ok(mut s) = self.scrobble_state.lock() { s.start(track.clone()); } - let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); + let fmt = Config::cached().ok().and_then(|c| c.display_format.clone()); notification::notify_track(&track, fmt.as_deref()); } } @@ -417,7 +417,7 @@ impl MprisPlayer { fn set_volume(&self, value: f64) { let level = (value * 100.0).clamp(0.0, 100.0) as u8; self.audio.set_volume(level as f32 / 100.0); - if let Ok(mut config) = Config::load() { + if let Ok(mut config) = Config::cached() { config.volume = Some(level); let _ = config.save(); } -- cgit v1.2.3