chore: resolve cargo fmt and clippy findings

This commit is contained in:
Frederic Laing 2026-09-08 21:16:15 +02:00 • committed by Michael Murphy
parent d77e99fb15
commit d9431dc367
6 changed files with 30 additions and 32 deletions

View file

@ -1,6 +1,5 @@
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use syn;
#[proc_macro_derive(CosmicConfigEntry, attributes(version, id, cosmic_config_entry))] #[proc_macro_derive(CosmicConfigEntry, attributes(version, id, cosmic_config_entry))]
pub fn cosmic_config_entry_derive(input: TokenStream) -> TokenStream { pub fn cosmic_config_entry_derive(input: TokenStream) -> TokenStream {

View file

@ -1,5 +1,5 @@
use iced_futures::futures::SinkExt;
use iced_futures::futures::channel::mpsc; use iced_futures::futures::channel::mpsc;
use iced_futures::futures::{SinkExt, Stream};
use iced_futures::stream; use iced_futures::stream;
use notify::RecommendedWatcher; use notify::RecommendedWatcher;
use std::borrow::Cow; use std::borrow::Cow;

View file

@ -756,6 +756,7 @@ impl Theme {
} }
/// Get the active theme based on the current theme mode. /// Get the active theme based on the current theme mode.
#[allow(clippy::result_large_err)]
pub fn get_active() -> Result<Self, (Vec<cosmic_config::Error>, Self)> { pub fn get_active() -> Result<Self, (Vec<cosmic_config::Error>, Self)> {
(|| { (|| {
(if ThemeMode::is_dark(&Config::new(Self::id(), Self::VERSION)?)? { (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)) .and_then(|theme_config| Self::get_entry(&theme_config))
} }
#[must_use]
/// Rebuild the current theme with the provided accent /// Rebuild the current theme with the provided accent
pub fn with_accent(&self, c: Srgba) -> Self { pub fn with_accent(&self, c: Srgba) -> Self {
let mut oklcha: Oklcha = c.into_color(); let mut oklcha: Oklcha = c.into_color();
@ -1097,7 +1097,7 @@ impl ThemeBuilder {
let container_alpha = alpha_map.blurred_alpha(frosted); let container_alpha = alpha_map.blurred_alpha(frosted);
let actual_alpha = 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 container_alpha
} else { } else {
1.0 1.0
@ -1167,9 +1167,14 @@ impl ThemeBuilder {
control_steps_array[0] control_steps_array[0]
}; };
component_hovered_overlay.alpha = 0.1; 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; 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 // Standard button background is neutral 7 with 25% opacity
let button_bg = control_steps_array[7].with_alpha(0.25); let button_bg = control_steps_array[7].with_alpha(0.25);
@ -1204,7 +1209,7 @@ impl ThemeBuilder {
); );
let primary = { 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 primary_container_bg_color
} else { } else {
get_surface_color(bg_index, 5, &step_array, is_dark, &control_steps_array[1]) 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_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; component_pressed_overlay.alpha = 0.2;
Container::new( Container::new(
@ -1357,7 +1362,7 @@ impl ThemeBuilder {
accent, accent,
on_bg_component, on_bg_component,
component_hovered_overlay, component_hovered_overlay,
component_pressed_overlay, background_pressed_overlay,
is_high_contrast, is_high_contrast,
control_steps_array[8], control_steps_array[8],
), ),
@ -1653,7 +1658,7 @@ impl ThemeBuilder {
/// but this represents the strength of the blur effect. /// but this represents the strength of the blur effect.
#[allow(missing_docs)] #[allow(missing_docs)]
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
pub enum BlurStrength { pub enum BlurStrength {
ExtremelyLow, ExtremelyLow,
ExtremelyLow2, ExtremelyLow2,
@ -1661,6 +1666,7 @@ pub enum BlurStrength {
VeryLow2, VeryLow2,
Low, Low,
Low2, Low2,
#[default]
Medium, Medium,
Medium2, Medium2,
High, High,
@ -1671,12 +1677,6 @@ pub enum BlurStrength {
ExtremelyHigh2, ExtremelyHigh2,
} }
impl Default for BlurStrength {
fn default() -> Self {
Self::Medium
}
}
impl TryFrom<u8> for BlurStrength { impl TryFrom<u8> for BlurStrength {
type Error = (); type Error = ();
@ -1701,6 +1701,7 @@ impl TryFrom<u8> for BlurStrength {
} }
} }
#[allow(missing_docs)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct AlphaMap { pub struct AlphaMap {
pub extremely_low: f32, pub extremely_low: f32,
@ -1719,6 +1720,7 @@ pub struct AlphaMap {
pub extremely_high_2: f32, pub extremely_high_2: f32,
} }
#[allow(missing_docs)]
impl AlphaMap { impl AlphaMap {
pub fn blurred_alpha(&self, blur: BlurStrength) -> f32 { pub fn blurred_alpha(&self, blur: BlurStrength) -> f32 {
match blur { match blur {

View file

@ -262,17 +262,15 @@ impl Theme {
return Ok(None); return Ok(None);
} }
if let Ok(metadata) = fs::symlink_metadata(path) { if let Ok(metadata) = fs::symlink_metadata(path)
if metadata.file_type().is_symlink() { && metadata.file_type().is_symlink()
if let Ok(actual_cosmic_css) = fs::read_link(path) { && let Ok(actual_cosmic_css) = fs::read_link(path)
let canonical_target = fs::canonicalize(&actual_cosmic_css)?; {
let canonical_base = fs::canonicalize(cosmic_css)?; let canonical_target = fs::canonicalize(&actual_cosmic_css)?;
return Ok(Some( let canonical_base = fs::canonicalize(cosmic_css)?;
canonical_target == canonical_base return Ok(Some(
|| canonical_target.starts_with(&canonical_base), canonical_target == canonical_base || canonical_target.starts_with(&canonical_base),
)); ));
}
}
} }
Ok(Some(false)) Ok(Some(false))
} }

View file

@ -111,7 +111,6 @@ inactive_colors={}
qt6ct_res?; qt6ct_res?;
Ok(()) Ok(())
} }
#[must_use]
#[cold] #[cold]
fn write_ct(&self, ct: &str, qpalette: &str) -> Result<(), OutputError> { fn write_ct(&self, ct: &str, qpalette: &str) -> Result<(), OutputError> {
let file_path = Self::get_qpalette_path(ct, self.is_dark)?; let file_path = Self::get_qpalette_path(ct, self.is_dark)?;
@ -139,7 +138,6 @@ inactive_colors={}
qt6ct_res?; qt6ct_res?;
Ok(()) Ok(())
} }
#[must_use]
#[cold] #[cold]
fn apply_ct(ct: &str, is_dark: bool) -> Result<(), OutputError> { fn apply_ct(ct: &str, is_dark: bool) -> Result<(), OutputError> {
let path = Self::get_conf_path(ct)?; let path = Self::get_conf_path(ct)?;
@ -213,7 +211,6 @@ inactive_colors={}
qt6ct_res?; qt6ct_res?;
Ok(()) Ok(())
} }
#[must_use]
#[cold] #[cold]
fn reset_ct(ct: &str) -> Result<(), OutputError> { fn reset_ct(ct: &str) -> Result<(), OutputError> {
let path = Self::get_conf_path(ct)?; let path = Self::get_conf_path(ct)?;
@ -249,7 +246,7 @@ inactive_colors={}
let Some(mut config_dir) = dirs::config_dir() else { let Some(mut config_dir) = dirs::config_dir() else {
return Err(OutputError::MissingConfigDir); return Err(OutputError::MissingConfigDir);
}; };
config_dir.push(&ct); config_dir.push(ct);
if !config_dir.exists() { if !config_dir.exists() {
fs::create_dir_all(&config_dir).map_err(OutputError::Io)?; 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 { let Some(mut config_dir) = dirs::config_dir() else {
return Err(OutputError::MissingConfigDir); return Err(OutputError::MissingConfigDir);
}; };
config_dir.push(&ct); config_dir.push(ct);
config_dir.push("colors"); config_dir.push("colors");
if !config_dir.exists() { if !config_dir.exists() {
fs::create_dir_all(&config_dir).map_err(OutputError::Io)?; fs::create_dir_all(&config_dir).map_err(OutputError::Io)?;

View file

@ -267,6 +267,7 @@ impl From<Theme> for VsTheme {
impl Theme { impl Theme {
#[cold] #[cold]
/// Applies the theme to VS Code's user settings.
pub fn apply_vs_code(self) -> Result<(), OutputError> { pub fn apply_vs_code(self) -> Result<(), OutputError> {
let vs_theme = VsTheme::from(self); let vs_theme = VsTheme::from(self);
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?; let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
@ -292,6 +293,7 @@ impl Theme {
} }
#[cold] #[cold]
/// Removes COSMIC theme settings from VS Code's user settings.
pub fn reset_vs_code() -> Result<(), OutputError> { pub fn reset_vs_code() -> Result<(), OutputError> {
let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?; let mut config_dir = dirs::config_dir().ok_or(OutputError::MissingConfigDir)?;
config_dir.extend(["Code", "User", "settings.json"]); config_dir.extend(["Code", "User", "settings.json"]);