From a7ca33b6eb5df72c92efdf4bb8b7b24a08e981d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= <150025636+git-f0x@users.noreply.github.com> Date: Mon, 27 Apr 2026 13:18:15 +0200 Subject: [PATCH] chore:: clippy --- daemon/src/lib.rs | 34 +++++++------ src/common.rs | 111 ++++++++++++++++++++---------------------- src/greeter.rs | 6 +-- src/locker.rs | 22 ++++----- src/networkmanager.rs | 20 ++++---- src/time.rs | 10 ++-- src/upower.rs | 38 +++++++-------- 7 files changed, 120 insertions(+), 121 deletions(-) diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 71f5ee5..842a92e 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -19,8 +19,8 @@ pub struct UserFilter { uid_max: u32, } -impl UserFilter { - pub fn new() -> Self { +impl Default for UserFilter { + fn default() -> Self { let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default(); let login_defs = whitespace_conf::parse(&login_defs_data); Self { @@ -34,6 +34,12 @@ impl UserFilter { .unwrap_or(65000), } } +} + +impl UserFilter { + pub fn new() -> Self { + Self::default() + } pub fn filter(&self, user: &pwd::Passwd) -> bool { if user.uid < self.uid_min || user.uid > self.uid_max { @@ -80,22 +86,18 @@ impl UserData { }) }); for (_, source) in self.bg_state.wallpapers.iter() { - match source { - //TODO: do not reread duplicate paths, cache data by path? - BgSource::Path(path) => { - if !self.bg_path_data.contains_key(path) { - match fs::read(path) { - Ok(bytes) => { - self.bg_path_data.insert(path.clone(), bytes); - } - Err(err) => { - tracing::error!("failed to read wallpaper {:?}: {:?}", path, err); - } - } + //TODO: do not reread duplicate paths, cache data by path? + if let BgSource::Path(path) = source + && !self.bg_path_data.contains_key(path) + { + match fs::read(path) { + Ok(bytes) => { + self.bg_path_data.insert(path.clone(), bytes); + } + Err(err) => { + tracing::error!("failed to read wallpaper {:?}: {:?}", path, err); } } - // Other types not supported - _ => {} } } } diff --git a/src/common.rs b/src/common.rs index 059f3fc..691a94c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -204,48 +204,48 @@ impl + Send + 'static> Common { self.update_wallpapers(user_data); // From cosmic-applet-input-sources - if let Some(keyboard_layouts) = &self.layouts_opt { - if let Some(xkb_config) = &user_data.xkb_config_opt { - self.active_layouts.clear(); - let config_layouts = xkb_config.layout.split_terminator(','); - let config_variants = xkb_config - .variant - .split_terminator(',') - .chain(std::iter::repeat("")); - 'outer: for (config_layout, config_variant) in config_layouts.zip(config_variants) { - for xkb_layout in keyboard_layouts.layouts() { - if config_layout != xkb_layout.name() { - continue; - } - if config_variant.is_empty() { - let active_layout = ActiveLayout { - description: xkb_layout.description().to_owned(), - layout: config_layout.to_owned(), - variant: config_variant.to_owned(), - }; - self.active_layouts.push(active_layout); - continue 'outer; - } - - let Some(xkb_variants) = xkb_layout.variants() else { - continue; + if let Some(keyboard_layouts) = &self.layouts_opt + && let Some(xkb_config) = &user_data.xkb_config_opt + { + self.active_layouts.clear(); + let config_layouts = xkb_config.layout.split_terminator(','); + let config_variants = xkb_config + .variant + .split_terminator(',') + .chain(std::iter::repeat("")); + 'outer: for (config_layout, config_variant) in config_layouts.zip(config_variants) { + for xkb_layout in keyboard_layouts.layouts() { + if config_layout != xkb_layout.name() { + continue; + } + if config_variant.is_empty() { + let active_layout = ActiveLayout { + description: xkb_layout.description().to_owned(), + layout: config_layout.to_owned(), + variant: config_variant.to_owned(), }; - for xkb_variant in xkb_variants { - if config_variant != xkb_variant.name() { - continue; - } - let active_layout = ActiveLayout { - description: xkb_variant.description().to_owned(), - layout: config_layout.to_owned(), - variant: config_variant.to_owned(), - }; - self.active_layouts.push(active_layout); - continue 'outer; + self.active_layouts.push(active_layout); + continue 'outer; + } + + let Some(xkb_variants) = xkb_layout.variants() else { + continue; + }; + for xkb_variant in xkb_variants { + if config_variant != xkb_variant.name() { + continue; } + let active_layout = ActiveLayout { + description: xkb_variant.description().to_owned(), + layout: config_layout.to_owned(), + variant: config_variant.to_owned(), + }; + self.active_layouts.push(active_layout); + continue 'outer; } } - tracing::info!("{:?}", self.active_layouts); } + tracing::info!("{:?}", self.active_layouts); } } @@ -271,20 +271,19 @@ impl + Send + 'static> Common { && !modifiers.alt() && matches!(key, Key::Character(_)) { - if let Some(text) = text { - if let Some((_, _, Some(value))) = &mut self.prompt_opt { - value.push_str(&text); - } + if let Some(text) = text + && let Some((_, _, Some(value))) = &mut self.prompt_opt + { + value.push_str(&text); } - if let Some(surface_id) = self.active_surface_id_opt { - if let Some(text_input_id) = self + if let Some(surface_id) = self.active_surface_id_opt + && let Some(text_input_id) = self .surface_names .get(&surface_id) .and_then(|id| self.text_input_ids.get(id)) - { - return widget::text_input::focus(text_input_id.clone()); - } + { + return widget::text_input::focus(text_input_id.clone()); } } } @@ -306,17 +305,15 @@ impl + Send + 'static> Common { Message::Prompt(prompt, secret, value_opt) => { let prompt_was_none = self.prompt_opt.is_none(); self.prompt_opt = Some((prompt, secret, value_opt)); - if prompt_was_none { - if let Some(surface_id) = self.active_surface_id_opt { - if let Some(text_input_id) = self - .surface_names - .get(&surface_id) - .and_then(|id| self.text_input_ids.get(id)) - { - tracing::info!("focus surface found id {:?}", text_input_id); - return widget::text_input::focus(text_input_id.clone()); - } - } + if prompt_was_none + && let Some(surface_id) = self.active_surface_id_opt + && let Some(text_input_id) = self + .surface_names + .get(&surface_id) + .and_then(|id| self.text_input_ids.get(id)) + { + tracing::info!("focus surface found id {:?}", text_input_id); + return widget::text_input::focus(text_input_id.clone()); } } Message::SessionLockEvent(lock_event) => { diff --git a/src/greeter.rs b/src/greeter.rs index 616ef33..d0b0405 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -482,7 +482,7 @@ impl App { .discard() } - fn menu(&self, id: SurfaceId) -> Element { + fn menu(&self, id: SurfaceId) -> Element<'_, Message> { let window_width = self .common .window_size @@ -1884,12 +1884,12 @@ impl cosmic::Application for App { } // Not used for layer surface window - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Self::Message> { unimplemented!() } /// Creates a view after each update. - fn view_window(&self, surface_id: SurfaceId) -> Element { + fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> { let img = self .common .surface_images diff --git a/src/locker.rs b/src/locker.rs index eed5f01..1a5f8a5 100644 --- a/src/locker.rs +++ b/src/locker.rs @@ -325,7 +325,7 @@ pub struct App { } impl App { - fn menu(&self, surface_id: SurfaceId) -> Element { + fn menu(&self, surface_id: SurfaceId) -> Element<'_, Message> { let window_width = self .common .window_size @@ -1132,10 +1132,10 @@ impl cosmic::Application for App { } self.spinner_rotation = 0.0; // Try to create lockfile when locking - if let Some(ref lockfile) = self.flags.lockfile_opt { - if let Err(err) = fs::File::create(lockfile) { - tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err); - } + if let Some(ref lockfile) = self.flags.lockfile_opt + && let Err(err) = fs::File::create(lockfile) + { + tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err); } // Tell compositor to lock return lock(); @@ -1165,10 +1165,10 @@ impl cosmic::Application for App { } self.spinner_rotation = 0.0; // Try to delete lockfile when unlocking - if let Some(ref lockfile) = self.flags.lockfile_opt { - if let Err(err) = fs::remove_file(lockfile) { - tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err); - } + if let Some(ref lockfile) = self.flags.lockfile_opt + && let Err(err) = fs::remove_file(lockfile) + { + tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err); } // Destroy lock surfaces @@ -1204,12 +1204,12 @@ impl cosmic::Application for App { } // Not used for layer surface window - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Self::Message> { unimplemented!() } /// Creates a view after each update. - fn view_window(&self, surface_id: SurfaceId) -> Element { + fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> { let img = self .common .surface_images diff --git a/src/networkmanager.rs b/src/networkmanager.rs index b8b04c0..06cba00 100644 --- a/src/networkmanager.rs +++ b/src/networkmanager.rs @@ -77,16 +77,16 @@ pub async fn handler(msg_tx: &mut mpsc::Sender>) -> Result< }; } Some(SpecificDevice::Wireless(wireless)) => { - if let Ok(ap) = wireless.active_access_point().await { - if let Ok(strength) = ap.strength().await { - // Wireless always overrides with the highest strength - icon = match icon { - NetworkIcon::Wireless(other_strength) => { - NetworkIcon::Wireless(cmp::max(strength, other_strength)) - } - _ => NetworkIcon::Wireless(strength), - }; - } + if let Ok(ap) = wireless.active_access_point().await + && let Ok(strength) = ap.strength().await + { + // Wireless always overrides with the highest strength + icon = match icon { + NetworkIcon::Wireless(other_strength) => { + NetworkIcon::Wireless(cmp::max(strength, other_strength)) + } + _ => NetworkIcon::Wireless(strength), + }; } } _ => {} diff --git a/src/time.rs b/src/time.rs index 49caf69..f3b1540 100644 --- a/src/time.rs +++ b/src/time.rs @@ -41,10 +41,10 @@ impl Time { } // Try language-only fallback (e.g., "en" from "en-US") - if let Some(lang) = cleaned_locale.split('-').next() { - if let Ok(locale) = Locale::try_from_str(lang) { - return locale; - } + if let Some(lang) = cleaned_locale.split('-').next() + && let Ok(locale) = Locale::try_from_str(lang) + { + return locale; } } } @@ -72,7 +72,7 @@ impl Time { .timezone .as_ref() .map(|tz| jiff::Timestamp::now().to_zoned(tz.clone())) - .unwrap_or_else(|| jiff::Zoned::now()); + .unwrap_or_else(jiff::Zoned::now); } pub fn format_date(&self) -> String { diff --git a/src/upower.rs b/src/upower.rs index fd950a0..3e5b96b 100644 --- a/src/upower.rs +++ b/src/upower.rs @@ -52,26 +52,26 @@ pub async fn handler(msg_tx: &mut mpsc::Sender>) -> Re loop { let mut info_opt = None; - if let Ok(mut percent) = dev.percentage().await { - if let Ok(state) = dev.state().await { - let threshold_enabled = dev.charge_threshold_enabled().await.unwrap_or_default(); - let mut capacity = dev.capacity().await.unwrap_or(100.); - if capacity <= 1. { - capacity = 100.; - } - - // compensate for declining battery capacity - percent = percent * 100. / capacity; - if matches!(state, BatteryState::FullyCharged) || percent >= 100. { - percent = 100.; - } - - info_opt = Some(( - percent, - state == BatteryState::Discharging, - threshold_enabled, - )); + if let Ok(mut percent) = dev.percentage().await + && let Ok(state) = dev.state().await + { + let threshold_enabled = dev.charge_threshold_enabled().await.unwrap_or_default(); + let mut capacity = dev.capacity().await.unwrap_or(100.); + if capacity <= 1. { + capacity = 100.; } + + // compensate for declining battery capacity + percent = percent * 100. / capacity; + if matches!(state, BatteryState::FullyCharged) || percent >= 100. { + percent = 100.; + } + + info_opt = Some(( + percent, + state == BatteryState::Discharging, + threshold_enabled, + )); } msg_tx.send(info_opt).await.unwrap();