From 985710b7c5cb35e246cfb2f2ed919338165224c2 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 18 Feb 2026 13:35:46 -0600 Subject: [PATCH] bugs: loading is nearly working... There is a bug with the slides not containing the text portions of the songs. There is also perhaps a bug in the logic to move to the next and previous slides --- src/core/file.rs | 35 ++++++++++++++++++---------------- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/core/file.rs b/src/core/file.rs index 32181a7..0fc9681 100644 --- a/src/core/file.rs +++ b/src/core/file.rs @@ -42,7 +42,7 @@ pub fn save( temp_dir.push(s); fs::create_dir_all(&temp_dir).into_diagnostic()?; let service_file = temp_dir.join("serviceitems.ron"); - dbg!(&service_file); + debug!(?service_file); fs::File::create(&service_file).into_diagnostic()?; match fs::File::options() .read(true) @@ -52,23 +52,21 @@ pub fn save( Ok(mut f) => { match f.write(ron.as_bytes()) { Ok(size) => { - dbg!(size); + debug!(size); } Err(e) => { error!(?e); - dbg!(&e); return Err(miette!("PROBS: {e}")); } } match tar.append_file("serviceitems.ron", &mut f) { Ok(()) => { - dbg!( + debug!( "should have added serviceitems.ron to the file" ); } Err(e) => { error!(?e); - dbg!(&e); return Err(miette!("PROBS: {e}")); } } @@ -113,19 +111,25 @@ pub fn save( } } if let Some(path) = audio { - let file_name = path.file_name().unwrap_or_default(); - dbg!(&path); - let mut file = fs::File::open(&path).into_diagnostic()?; - tar.append_file(file_name, &mut file) - .into_diagnostic()?; + if path.exists() { + let file_name = path.file_name().unwrap_or_default(); + debug!(?path); + let mut file = + fs::File::open(&path).into_diagnostic()?; + tar.append_file(file_name, &mut file) + .into_diagnostic()?; + } } if let Some(background) = background { let path = background.path; - dbg!(&path); - let file_name = path.file_name().unwrap_or_default(); - let mut file = fs::File::open(&path).into_diagnostic()?; - tar.append_file(file_name, &mut file) - .into_diagnostic()?; + if path.exists() { + debug!(?path); + let file_name = path.file_name().unwrap_or_default(); + let mut file = + fs::File::open(&path).into_diagnostic()?; + tar.append_file(file_name, &mut file) + .into_diagnostic()?; + } } } @@ -133,7 +137,6 @@ pub fn save( Ok(()) => (), Err(e) => { error!(?e); - dbg!(&e); return Err(miette!("tar error: {e}")); } } diff --git a/src/main.rs b/src/main.rs index 36d2f20..a906a64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use core::slide::{ }; use cosmic::app::{Core, Settings, Task}; use cosmic::cosmic_config::{Config, CosmicConfigEntry}; -use cosmic::dialog::file_chooser::save; +use cosmic::dialog::file_chooser::{open, save}; use cosmic::iced::alignment::Vertical; use cosmic::iced::keyboard::{Key, Modifiers}; use cosmic::iced::window::{Mode, Position}; @@ -221,6 +221,7 @@ enum Message { New, Open, OpenFile(PathBuf), + OpenLoadItems(Vec), Save, SaveAsDialog, SaveAs(PathBuf), @@ -1498,23 +1499,50 @@ impl cosmic::Application for App { } Message::Open => { debug!("Open file"); - Task::none() + Task::perform(open_dialog(), |res| match res { + Ok(file) => { + cosmic::Action::App(Message::OpenFile(file)) + } + Err(e) => { + error!( + ?e, + "There was an error during opening" + ); + cosmic::Action::None + } + }) } Message::OpenFile(file) => { debug!(?file, "opening file"); + Task::perform( + async move { file::load(file) }, + |res| match res { + Ok(items) => cosmic::Action::App( + Message::OpenLoadItems(items), + ), + Err(e) => { + error!(?e); + cosmic::Action::None + } + }, + ) + } + Message::OpenLoadItems(items) => { + self.service = items.clone(); + self.presenter.service = items; Task::none() } Message::Save => { let service = self.service.clone(); - let file1 = self.file.clone(); - let file2 = self.file.clone(); + let file = self.file.clone(); + let file_name = self.file.file_name().expect("Since we are saving we should have given a name by now").to_owned(); Task::perform( - async move { file::save(service, file1, true) }, + async move { file::save(service, file, true) }, move |res| match res { Ok(()) => { tracing::info!( "saving file to: {:?}", - file2 + file_name ); cosmic::Action::None } @@ -2196,3 +2224,12 @@ async fn save_as_dialog() -> Result { ) })? } + +async fn open_dialog() -> Result { + let dialog = open::Dialog::new(); + open::file(dialog).await.into_diagnostic().map(|response| { + response.url().to_file_path().map_err(|e| { + miette!("Can't convert to file path: {:?}", e) + }) + })? +}