From f3d0cd5459fd1d9675714ebe0c6fe8639c2177cb Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 17 Aug 2025 06:08:49 -0500 Subject: [PATCH] slide changing works now --- src/main.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++- src/ui/presenter.rs | 24 ++++++++++++++++++--- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index d0e4eb0..471e3e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -597,6 +597,8 @@ impl cosmic::Application for App { slide, ), ); + self.current_item = + (item_index, slide_index + 1); Task::none() } else { debug!("Slides are not longer"); @@ -613,7 +615,54 @@ impl cosmic::Application for App { Task::none() } } - presenter::Action::PrevSlide => todo!(), + presenter::Action::PrevSlide => { + let slide_index = self.current_item.1; + let item_index = self.current_item.0; + if let Some(item) = + self.service.get(item_index) + { + if slide_index != 0 { + let slide = item.slides + [slide_index - 1] + .clone(); + self.presenter.update( + presenter::Message::SlideChange( + slide, + ), + ); + self.current_item = + (item_index, slide_index - 1); + Task::none() + } else if slide_index == 0 + && item_index == 0 + { + Task::none() + } else { + debug!("Change slide to previous items slides"); + let previous_item_slides_length = + if let Some(item) = self + .service + .get(item_index - 1) + { + item.slides.len() + } else { + 0 + }; + self.current_item = ( + item_index - 1, + previous_item_slides_length - 1, + ); + if let Some(item) = + self.service.get(item_index - 1) + { + self.presenter.update(presenter::Message::SlideChange(item.slides[previous_item_slides_length - 1].clone())); + } + Task::none() + } + } else { + Task::none() + } + } } } Message::Library(message) => { diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index f732019..135ba30 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -244,13 +244,31 @@ impl Presenter { let audio = PathBuf::from(audio); debug!("{:?}", audio); if audio.exists() { - match &self.audio { - Some(aud) if aud != &audio => { + let old_audio = self.audio.clone(); + match old_audio { + Some(current_audio) + if current_audio != audio => + { self.audio = Some(audio.clone()); + debug!( + ?audio, + ?current_audio, + "starting audio" + ); tasks.push(self.start_audio()); } - Some(_) => (), + Some(current_audio) => { + debug!( + ?audio, + ?current_audio, + "could not find audio" + ); + } None => { + debug!( + ?audio, + "could not find audio" + ); self.audio = Some(audio.clone()); tasks.push(self.start_audio()); }