From 0d7e5b9285434e527d02a1e5af2f7dd473a4cf47 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 15 Feb 2026 11:17:30 -0600 Subject: [PATCH] fixing a lot of lints --- src/core/file.rs | 14 ++--- src/core/service_items.rs | 1 + src/core/slide.rs | 18 +----- src/core/songs.rs | 122 +++++++++++++++++++------------------- src/main.rs | 36 +++++++---- src/ui/song_editor.rs | 7 ++- src/ui/text_svg.rs | 27 ++++----- 7 files changed, 109 insertions(+), 116 deletions(-) diff --git a/src/core/file.rs b/src/core/file.rs index 476054b..a1009ef 100644 --- a/src/core/file.rs +++ b/src/core/file.rs @@ -25,9 +25,13 @@ pub fn save( let save_file = File::create(path).into_diagnostic()?; let ron = process_service_items(&list)?; - let encoder = Encoder::new(save_file, 3).unwrap().auto_finish(); + let encoder = Encoder::new(save_file, 3) + .expect("file encoder shouldn't fail") + .auto_finish(); let mut tar = Builder::new(encoder); - let mut temp_dir = dirs::data_dir().unwrap(); + let mut temp_dir = dirs::data_dir().expect( + "there should be a data directory, ~/.local/share/ for linux, but couldn't find it", + ); temp_dir.push("lumina"); let mut s: String = iter::repeat_with(fastrand::alphanumeric).take(5).collect(); @@ -40,7 +44,6 @@ pub fn save( match fs::File::options() .read(true) .write(true) - .create(true) .open(service_file) { Ok(mut f) => { @@ -135,10 +138,7 @@ pub fn save( fn process_service_items(items: &Vec) -> Result { Ok(items .iter() - .filter_map(|item| { - let ron = ron::ser::to_string(item); - ron.ok() - }) + .filter_map(|item| ron::ser::to_string(item).ok()) .collect()) } diff --git a/src/core/service_items.rs b/src/core/service_items.rs index 8a4481b..2d13a27 100644 --- a/src/core/service_items.rs +++ b/src/core/service_items.rs @@ -368,6 +368,7 @@ impl From<&Presentation> for ServiceItem { } } +#[allow(unused)] impl Service { fn add_item( &mut self, diff --git a/src/core/slide.rs b/src/core/slide.rs index 32ed0bb..832a327 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -1,3 +1,4 @@ +#![allow(clippy::similar_names, unused)] use cosmic::widget::image::Handle; // use cosmic::dialog::ashpd::url::Url; use crisp::types::{Keyword, Symbol, Value}; @@ -48,13 +49,6 @@ pub enum BackgroundKind { Html, } -#[derive(Debug, Clone, Default)] -struct Image { - pub source: String, - pub fit: String, - pub children: Vec, -} - #[derive( Clone, Copy, @@ -391,10 +385,6 @@ impl Slide { self.id = index; } - pub(crate) fn text_to_image(&self) { - todo!() - } - // pub fn slides_from_item(item: &ServiceItem) -> Result> { // todo!() // } @@ -750,12 +740,6 @@ impl SlideBuilder { } } -impl Image { - fn new() -> Self { - Default::default() - } -} - #[cfg(test)] mod test { use pretty_assertions::assert_eq; diff --git a/src/core/songs.rs b/src/core/songs.rs index 23ebce2..62ee8a6 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -781,7 +781,7 @@ pub async fn get_song_from_db( index: i32, db: &mut SqliteConnection, ) -> Result { - let row = query(r#"SELECT verse_order, font_size, background_type, horizontal_text_alignment, vertical_text_alignment, title, font, background, lyrics, ccli, author, audio, stroke_size, stroke_color, shadow_color, shadow_size, shadow_offset_x, shadow_offset_y, id from songs where id = $1"#).bind(index).fetch_one(db).await.into_diagnostic()?; + let row = query("SELECT verse_order, font_size, background_type, horizontal_text_alignment, vertical_text_alignment, title, font, background, lyrics, ccli, author, audio, stroke_size, stroke_color, shadow_color, shadow_size, shadow_offset_x, shadow_offset_y, id from songs where id = $1").bind(index).fetch_one(db).await.into_diagnostic()?; Song::from_row(&row).into_diagnostic() } @@ -799,7 +799,7 @@ impl Model { pub async fn load_from_db(&mut self, db: &mut SqlitePool) { // static DATABASE_URL: &str = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3"; let db1 = db.acquire().await.unwrap(); - let result = query(r"SELECT verse_order, font_size, background_type, horizontal_text_alignment, vertical_text_alignment, title, font, background, lyrics, ccli, author, audio, stroke_size, shadow_size, stroke_color, shadow_color, shadow_offset_x, shadow_offset_y, id from songs").fetch_all(&mut db1.detach()).await; + let result = query("SELECT verse_order, font_size, background_type, horizontal_text_alignment, vertical_text_alignment, title, font, background, lyrics, ccli, author, audio, stroke_size, shadow_size, stroke_color, shadow_color, shadow_offset_x, shadow_offset_y, id from songs").fetch_all(&mut db1.detach()).await; match result { Ok(s) => { for song in s { @@ -1034,67 +1034,67 @@ impl Song { // old implementation // --------------------------------- - let mut lyric_list = Vec::new(); - if self.lyrics.is_none() { - return Err(miette!("There is no lyrics here")); - } else if self.verse_order.is_none() { - return Err(miette!("There is no verse_order here")); - } else if self - .verse_order - .clone() - .is_some_and(|v| v.is_empty()) - { - return Err(miette!("There is no verse_order here")); - } - if let Some(raw_lyrics) = self.lyrics.clone() { - let raw_lyrics = raw_lyrics.as_str(); - let verse_order = self.verses.clone(); + // let mut lyric_list = Vec::new(); + // if self.lyrics.is_none() { + // return Err(miette!("There is no lyrics here")); + // } else if self.verse_order.is_none() { + // return Err(miette!("There is no verse_order here")); + // } else if self + // .verse_order + // .clone() + // .is_some_and(|v| v.is_empty()) + // { + // return Err(miette!("There is no verse_order here")); + // } + // if let Some(raw_lyrics) = self.lyrics.clone() { + // let raw_lyrics = raw_lyrics.as_str(); + // let verse_order = self.verses.clone(); - let mut lyric_map = HashMap::new(); - let mut verse_title = String::new(); - let mut lyric = String::new(); - for (i, line) in raw_lyrics.split('\n').enumerate() { - if VERSE_KEYWORDS.contains(&line) { - if i != 0 { - lyric_map.insert(verse_title, lyric); - lyric = String::new(); - verse_title = line.to_string(); - } else { - verse_title = line.to_string(); - } - } else { - lyric.push_str(line); - lyric.push('\n'); - } - } - lyric_map.insert(verse_title, lyric); + // let mut lyric_map = HashMap::new(); + // let mut verse_title = String::new(); + // let mut lyric = String::new(); + // for (i, line) in raw_lyrics.split('\n').enumerate() { + // if VERSE_KEYWORDS.contains(&line) { + // if i != 0 { + // lyric_map.insert(verse_title, lyric); + // lyric = String::new(); + // verse_title = line.to_string(); + // } else { + // verse_title = line.to_string(); + // } + // } else { + // lyric.push_str(line); + // lyric.push('\n'); + // } + // } + // lyric_map.insert(verse_title, lyric); - for verse in verse_order.unwrap_or_default() { - let verse_name = &verse.get_name(); - if let Some(lyric) = lyric_map.get(verse_name) { - if lyric.contains("\n\n") { - let split_lyrics: Vec<&str> = - lyric.split("\n\n").collect(); - for lyric in split_lyrics { - if lyric.is_empty() { - continue; - } - lyric_list.push(lyric.to_string()); - } - continue; - } - lyric_list.push(lyric.clone()); - } else { - // error!("NOT WORKING!"); - } - } - // for lyric in lyric_list.iter() { - // debug!(lyric = ?lyric) - // } - Ok(lyric_list) - } else { - Err(miette!("There are no lyrics")) - } + // for verse in verse_order.unwrap_or_default() { + // let verse_name = &verse.get_name(); + // if let Some(lyric) = lyric_map.get(verse_name) { + // if lyric.contains("\n\n") { + // let split_lyrics: Vec<&str> = + // lyric.split("\n\n").collect(); + // for lyric in split_lyrics { + // if lyric.is_empty() { + // continue; + // } + // lyric_list.push(lyric.to_string()); + // } + // continue; + // } + // lyric_list.push(lyric.clone()); + // } else { + // // error!("NOT WORKING!"); + // } + // } + // // for lyric in lyric_list.iter() { + // // debug!(lyric = ?lyric) + // // } + // Ok(lyric_list) + // } else { + // Err(miette!("There are no lyrics")) + // } } pub fn update_verse_name( diff --git a/src/main.rs b/src/main.rs index 87a045b..f472057 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(clippy::option_if_let_else)] use clap::Parser; use core::service_items::ServiceItem; use core::slide::{ @@ -436,7 +437,7 @@ impl cosmic::Application for App { batch.push(app.show_window()); } - batch.push(app.add_library()); + batch.push(add_library()); // batch.push(app.add_service(items, Arc::clone(&fontdb))); let batch = Task::batch(batch); (app, batch) @@ -1671,7 +1672,7 @@ impl cosmic::Application for App { if let Some(library) = &self.library { library.view().map(Message::Library) } else { - Space::new(0, 0).into() + Element::from(Space::new(0, 0)) }, ) .style(nav_bar_style), @@ -1814,14 +1815,8 @@ where .map(|id| cosmic::Action::App(Message::WindowOpened(id))) } - fn add_library(&self) -> Task { - Task::perform(async move { Library::new().await }, |x| { - cosmic::Action::App(Message::AddLibrary(x)) - }) - } - fn search(&self, query: String) -> Task { - if let Some(library) = self.library.clone() { + self.library.clone().map_or_else(Task::none, |library| { Task::perform( async move { library.search_items(query).await }, |items| { @@ -1830,9 +1825,19 @@ where )) }, ) - } else { - Task::none() - } + }) + // if let Some(library) = self.library.clone() { + // Task::perform( + // async move { library.search_items(query).await }, + // |items| { + // cosmic::Action::App(Message::UpdateSearchResults( + // items, + // )) + // }, + // ) + // } else { + // Task::none() + // } } fn process_key_press( @@ -1906,6 +1911,7 @@ where } } + #[allow(clippy::too_many_lines)] fn service_list(&self) -> Element { let list = self.service.iter().enumerate().map(|(index, item)| { @@ -2178,6 +2184,12 @@ where } } +fn add_library() -> Task { + Task::perform(async move { Library::new().await }, |x| { + cosmic::Action::App(Message::AddLibrary(x)) + }) +} + async fn save_as_dialog() -> Result { let dialog = save::Dialog::new(); diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 9d9dbdc..63f2040 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -1,3 +1,4 @@ +#![allow(clippy::similar_names)] use std::{ fmt::Display, io::{self}, @@ -14,7 +15,6 @@ use cosmic::{ alignment::Vertical, color, font::{Style, Weight}, - futures::StreamExt, task, }, iced_core::widget::tree, @@ -153,7 +153,7 @@ pub enum Message { } #[derive(Debug, Clone)] -struct Face(fontdb::FaceInfo); +pub struct Face(fontdb::FaceInfo); impl Display for Face { fn fmt( @@ -1841,6 +1841,7 @@ impl SongEditor { } } +#[allow(clippy::unreadable_literal)] fn verse_chip( verse: VerseName, index: Option, @@ -1854,7 +1855,7 @@ fn verse_chip( } = theme::spacing(); const VERSE_COLOR: cosmic::iced::Color = color!(0xf26430); - const CHORUS_COLOR: cosmic::iced::Color = color!(0x3A86ff); + const CHORUS_COLOR: cosmic::iced::Color = color!(0x3a86ff); const BRIDGE_COLOR: cosmic::iced::Color = color!(0x47e5bc); const INSTRUMENTAL_COLOR: cosmic::iced::Color = color!(0xd90368); const OTHER_COLOR: cosmic::iced::Color = color!(0xffd400); diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 0224a28..e48ef2c 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -408,22 +408,17 @@ impl TextSvg { } final_svg.push('>'); - let text: String = self - .text - .lines() - .enumerate() - .map(|(index, text)| { - format!( - "{}", - (index as f32).mul_add( - text_and_line_spacing, - starting_y_position - ), - text - ) - }) - .collect(); - final_svg.push_str(&text); + for (index, text) in self.text.lines().enumerate() { + let tspan = format!( + "{}", + (index as f32).mul_add( + text_and_line_spacing, + starting_y_position + ), + text + ); + final_svg.push_str(&tspan); + } final_svg.push_str("");