From d9431dc3670575602385e1e2523600ba5315508c Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Tue, 8 Sep 2026 21:16:15 +0200 Subject: [PATCH] chore: resolve cargo fmt and clippy findings --- cosmic-config-derive/src/lib.rs | 1 - cosmic-config/src/subscription.rs | 2 +- cosmic-theme/src/model/theme.rs | 30 +++++++++++++----------- cosmic-theme/src/output/gtk4_output.rs | 20 +++++++--------- cosmic-theme/src/output/qt56ct_output.rs | 7 ++---- cosmic-theme/src/output/vs_code.rs | 2 ++ 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/cosmic-config-derive/src/lib.rs b/cosmic-config-derive/src/lib.rs index 1c9461b8..1ca2a3f6 100644 --- a/cosmic-config-derive/src/lib.rs +++ b/cosmic-config-derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(CosmicConfigEntry, attributes(version, id, cosmic_config_entry))] pub fn cosmic_config_entry_derive(input: TokenStream) -> TokenStream { diff --git a/cosmic-config/src/subscription.rs b/cosmic-config/src/subscription.rs index f0387877..124b432a 100644 --- a/cosmic-config/src/subscription.rs +++ b/cosmic-config/src/subscription.rs @@ -1,5 +1,5 @@ +use iced_futures::futures::SinkExt; use iced_futures::futures::channel::mpsc; -use iced_futures::futures::{SinkExt, Stream}; use iced_futures::stream; use notify::RecommendedWatcher; use std::borrow::Cow; diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index 5974523b..98cb209c 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -756,6 +756,7 @@ impl Theme { } /// Get the active theme based on the current theme mode. + #[allow(clippy::result_large_err)] pub fn get_active() -> Result, Self)> { (|| { (if ThemeMode::is_dark(&Config::new(Self::id(), Self::VERSION)?)? { @@ -768,7 +769,6 @@ impl Theme { .and_then(|theme_config| Self::get_entry(&theme_config)) } - #[must_use] /// Rebuild the current theme with the provided accent pub fn with_accent(&self, c: Srgba) -> Self { let mut oklcha: Oklcha = c.into_color(); @@ -1097,7 +1097,7 @@ impl ThemeBuilder { let container_alpha = alpha_map.blurred_alpha(frosted); let actual_alpha = - if (frosted_windows || frosted_system_interface || frosted_panel || frosted_applets) { + if frosted_windows || frosted_system_interface || frosted_panel || frosted_applets { container_alpha } else { 1.0 @@ -1167,9 +1167,14 @@ impl ThemeBuilder { control_steps_array[0] }; component_hovered_overlay.alpha = 0.1; - + let mut background_pressed_overlay = component_hovered_overlay; + background_pressed_overlay.alpha = 0.2; + #[allow(unused_assignments)] let mut component_pressed_overlay = component_hovered_overlay; - component_pressed_overlay.alpha = 0.2; + #[allow(unused_assignments)] + { + component_pressed_overlay.alpha = 0.2; + } // Standard button background is neutral 7 with 25% opacity let button_bg = control_steps_array[7].with_alpha(0.25); @@ -1204,7 +1209,7 @@ impl ThemeBuilder { ); let primary = { - let mut container_bg = if let Some(primary_container_bg_color) = primary_container_bg { + let container_bg = if let Some(primary_container_bg_color) = primary_container_bg { primary_container_bg_color } else { get_surface_color(bg_index, 5, &step_array, is_dark, &control_steps_array[1]) @@ -1222,7 +1227,7 @@ impl ThemeBuilder { }; component_hovered_overlay.alpha = 0.1; - component_pressed_overlay = component_hovered_overlay; + let mut component_pressed_overlay = component_hovered_overlay; component_pressed_overlay.alpha = 0.2; Container::new( @@ -1357,7 +1362,7 @@ impl ThemeBuilder { accent, on_bg_component, component_hovered_overlay, - component_pressed_overlay, + background_pressed_overlay, is_high_contrast, control_steps_array[8], ), @@ -1653,7 +1658,7 @@ impl ThemeBuilder { /// but this represents the strength of the blur effect. #[allow(missing_docs)] #[repr(u8)] -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Default)] pub enum BlurStrength { ExtremelyLow, ExtremelyLow2, @@ -1661,6 +1666,7 @@ pub enum BlurStrength { VeryLow2, Low, Low2, + #[default] Medium, Medium2, High, @@ -1671,12 +1677,6 @@ pub enum BlurStrength { ExtremelyHigh2, } -impl Default for BlurStrength { - fn default() -> Self { - Self::Medium - } -} - impl TryFrom for BlurStrength { type Error = (); @@ -1701,6 +1701,7 @@ impl TryFrom for BlurStrength { } } +#[allow(missing_docs)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct AlphaMap { pub extremely_low: f32, @@ -1719,6 +1720,7 @@ pub struct AlphaMap { pub extremely_high_2: f32, } +#[allow(missing_docs)] impl AlphaMap { pub fn blurred_alpha(&self, blur: BlurStrength) -> f32 { match blur { diff --git a/cosmic-theme/src/output/gtk4_output.rs b/cosmic-theme/src/output/gtk4_output.rs index 16a3c36e..74b7e266 100644 --- a/cosmic-theme/src/output/gtk4_output.rs +++ b/cosmic-theme/src/output/gtk4_output.rs @@ -262,17 +262,15 @@ impl Theme { return Ok(None); } - if let Ok(metadata) = fs::symlink_metadata(path) { - if metadata.file_type().is_symlink() { - if let Ok(actual_cosmic_css) = fs::read_link(path) { - let canonical_target = fs::canonicalize(&actual_cosmic_css)?; - let canonical_base = fs::canonicalize(cosmic_css)?; - return Ok(Some( - canonical_target == canonical_base - || canonical_target.starts_with(&canonical_base), - )); - } - } + if let Ok(metadata) = fs::symlink_metadata(path) + && metadata.file_type().is_symlink() + && let Ok(actual_cosmic_css) = fs::read_link(path) + { + let canonical_target = fs::canonicalize(&actual_cosmic_css)?; + let canonical_base = fs::canonicalize(cosmic_css)?; + return Ok(Some( + canonical_target == canonical_base || canonical_target.starts_with(&canonical_base), + )); } Ok(Some(false)) } diff --git a/cosmic-theme/src/output/qt56ct_output.rs b/cosmic-theme/src/output/qt56ct_output.rs index 16df211f..a4c0b54b 100644 --- a/cosmic-theme/src/output/qt56ct_output.rs +++ b/cosmic-theme/src/output/qt56ct_output.rs @@ -111,7 +111,6 @@ inactive_colors={} qt6ct_res?; Ok(()) } - #[must_use] #[cold] fn write_ct(&self, ct: &str, qpalette: &str) -> Result<(), OutputError> { let file_path = Self::get_qpalette_path(ct, self.is_dark)?; @@ -139,7 +138,6 @@ inactive_colors={} qt6ct_res?; Ok(()) } - #[must_use] #[cold] fn apply_ct(ct: &str, is_dark: bool) -> Result<(), OutputError> { let path = Self::get_conf_path(ct)?; @@ -213,7 +211,6 @@ inactive_colors={} qt6ct_res?; Ok(()) } - #[must_use] #[cold] fn reset_ct(ct: &str) -> Result<(), OutputError> { let path = Self::get_conf_path(ct)?; @@ -249,7 +246,7 @@ inactive_colors={} let Some(mut config_dir) = dirs::config_dir() else { return Err(OutputError::MissingConfigDir); }; - config_dir.push(&ct); + config_dir.push(ct); if !config_dir.exists() { fs::create_dir_all(&config_dir).map_err(OutputError::Io)?; } @@ -272,7 +269,7 @@ inactive_colors={} let Some(mut config_dir) = dirs::config_dir() else { return Err(OutputError::MissingConfigDir); }; - config_dir.push(&ct); + config_dir.push(ct); config_dir.push("colors"); if !config_dir.exists() { fs::create_dir_all(&config_dir).map_err(OutputError::Io)?; diff --git a/cosmic-theme/src/output/vs_code.rs b/cosmic-theme/src/output/vs_code.rs index 43c36bb6..f0a5168e 100644 --- a/cosmic-theme/src/output/vs_code.rs +++ b/cosmic-theme/src/output/vs_code.rs @@ -267,6 +267,7 @@ impl From for VsTheme { impl Theme { #[cold] + /// Applies the theme to VS Code's user settings. pub fn apply_vs_code(self) -> Result<(), OutputError> { let vs_theme = VsTheme::from(self); let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?; @@ -292,6 +293,7 @@ impl Theme { } #[cold] + /// Removes COSMIC theme settings from VS Code's user settings. pub fn reset_vs_code() -> Result<(), OutputError> { let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?; config_dir.extend(["Code", "User", "settings.json"]);