From 8b0317f88d9c010bb1016888ea33265e6eac10b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 4 Nov 2025 22:33:32 +0000 Subject: [PATCH] refactor: Simplify FlacCacheSink playlist registration using logic_mut() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve the architecture by configuring the playlist handle directly in register_playlist() instead of deferring it to run(). Changes: - Remove playlist_handle_pending field (no longer needed) - register_playlist() now calls logic_mut() to configure immediately - run() becomes a simple delegation with no configuration logic - Follows proper pattern: configuration before run(), not during run() This is cleaner than the previous approach which used a pending field and transferred it during run(). The new approach: 1. User calls register_playlist() → directly configures logic 2. User calls run() → simple delegation to inner.run() Architecture now properly separates configuration from execution. --- pmoaudio-ext/src/sinks/flac_cache_sink.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pmoaudio-ext/src/sinks/flac_cache_sink.rs b/pmoaudio-ext/src/sinks/flac_cache_sink.rs index 62be634e..f1924a9c 100755 --- a/pmoaudio-ext/src/sinks/flac_cache_sink.rs +++ b/pmoaudio-ext/src/sinks/flac_cache_sink.rs @@ -251,8 +251,6 @@ impl NodeLogic for FlacCacheSinkLogic { pub struct FlacCacheSink { inner: Node, - #[cfg(feature = "playlist")] - playlist_handle_pending: Option>, } impl FlacCacheSink { @@ -297,8 +295,6 @@ impl FlacCacheSink { let logic = FlacCacheSinkLogic::new(cache, covers, collection, encoder_options, 8); Self { inner: Node::new_with_input(logic, channel_size), - #[cfg(feature = "playlist")] - playlist_handle_pending: None, } } @@ -309,7 +305,7 @@ impl FlacCacheSink { /// * `handle` - WriteHandle de la playlist qui recevra les pk des tracks #[cfg(feature = "playlist")] pub fn register_playlist(&mut self, handle: pmoplaylist::WriteHandle) { - self.playlist_handle_pending = Some(Arc::new(handle)); + self.inner.logic_mut().set_playlist_handle(Arc::new(handle)); } } @@ -649,13 +645,7 @@ impl AudioPipelineNode for FlacCacheSink { panic!("FlacCacheSink is a terminal sink and cannot have children"); } - async fn run(mut self: Box, stop_token: CancellationToken) -> Result<(), AudioError> { - // Transférer le playlist_handle_pending à la logique si présent - #[cfg(feature = "playlist")] - if let Some(handle) = self.playlist_handle_pending.take() { - self.inner.logic_mut().set_playlist_handle(handle); - } - + async fn run(self: Box, stop_token: CancellationToken) -> Result<(), AudioError> { Box::new(self.inner).run(stop_token).await } }