chore:: clippy

This commit is contained in:
Vukašin Vojinović 2026-04-27 13:18:15 +02:00 committed by Michael Murphy
parent ec1b80534a
commit a7ca33b6eb
7 changed files with 120 additions and 121 deletions

View file

@ -19,8 +19,8 @@ pub struct UserFilter {
uid_max: u32, uid_max: u32,
} }
impl UserFilter { impl Default for UserFilter {
pub fn new() -> Self { fn default() -> Self {
let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default(); let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default();
let login_defs = whitespace_conf::parse(&login_defs_data); let login_defs = whitespace_conf::parse(&login_defs_data);
Self { Self {
@ -34,6 +34,12 @@ impl UserFilter {
.unwrap_or(65000), .unwrap_or(65000),
} }
} }
}
impl UserFilter {
pub fn new() -> Self {
Self::default()
}
pub fn filter(&self, user: &pwd::Passwd) -> bool { pub fn filter(&self, user: &pwd::Passwd) -> bool {
if user.uid < self.uid_min || user.uid > self.uid_max { 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() { for (_, source) in self.bg_state.wallpapers.iter() {
match source { //TODO: do not reread duplicate paths, cache data by path?
//TODO: do not reread duplicate paths, cache data by path? if let BgSource::Path(path) = source
BgSource::Path(path) => { && !self.bg_path_data.contains_key(path)
if !self.bg_path_data.contains_key(path) { {
match fs::read(path) { match fs::read(path) {
Ok(bytes) => { Ok(bytes) => {
self.bg_path_data.insert(path.clone(), bytes); self.bg_path_data.insert(path.clone(), bytes);
} }
Err(err) => { Err(err) => {
tracing::error!("failed to read wallpaper {:?}: {:?}", path, err); tracing::error!("failed to read wallpaper {:?}: {:?}", path, err);
}
}
} }
} }
// Other types not supported
_ => {}
} }
} }
} }

View file

@ -204,48 +204,48 @@ impl<M: From<Message> + Send + 'static> Common<M> {
self.update_wallpapers(user_data); self.update_wallpapers(user_data);
// From cosmic-applet-input-sources // From cosmic-applet-input-sources
if let Some(keyboard_layouts) = &self.layouts_opt { if let Some(keyboard_layouts) = &self.layouts_opt
if let Some(xkb_config) = &user_data.xkb_config_opt { && let Some(xkb_config) = &user_data.xkb_config_opt
self.active_layouts.clear(); {
let config_layouts = xkb_config.layout.split_terminator(','); self.active_layouts.clear();
let config_variants = xkb_config let config_layouts = xkb_config.layout.split_terminator(',');
.variant let config_variants = xkb_config
.split_terminator(',') .variant
.chain(std::iter::repeat("")); .split_terminator(',')
'outer: for (config_layout, config_variant) in config_layouts.zip(config_variants) { .chain(std::iter::repeat(""));
for xkb_layout in keyboard_layouts.layouts() { 'outer: for (config_layout, config_variant) in config_layouts.zip(config_variants) {
if config_layout != xkb_layout.name() { for xkb_layout in keyboard_layouts.layouts() {
continue; if config_layout != xkb_layout.name() {
} continue;
if config_variant.is_empty() { }
let active_layout = ActiveLayout { if config_variant.is_empty() {
description: xkb_layout.description().to_owned(), let active_layout = ActiveLayout {
layout: config_layout.to_owned(), description: xkb_layout.description().to_owned(),
variant: config_variant.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;
}; };
for xkb_variant in xkb_variants { self.active_layouts.push(active_layout);
if config_variant != xkb_variant.name() { continue 'outer;
continue; }
}
let active_layout = ActiveLayout { let Some(xkb_variants) = xkb_layout.variants() else {
description: xkb_variant.description().to_owned(), continue;
layout: config_layout.to_owned(), };
variant: config_variant.to_owned(), for xkb_variant in xkb_variants {
}; if config_variant != xkb_variant.name() {
self.active_layouts.push(active_layout); continue;
continue 'outer;
} }
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<M: From<Message> + Send + 'static> Common<M> {
&& !modifiers.alt() && !modifiers.alt()
&& matches!(key, Key::Character(_)) && matches!(key, Key::Character(_))
{ {
if let Some(text) = text { if let Some(text) = text
if let Some((_, _, Some(value))) = &mut self.prompt_opt { && let Some((_, _, Some(value))) = &mut self.prompt_opt
value.push_str(&text); {
} value.push_str(&text);
} }
if let Some(surface_id) = self.active_surface_id_opt { if let Some(surface_id) = self.active_surface_id_opt
if let Some(text_input_id) = self && let Some(text_input_id) = self
.surface_names .surface_names
.get(&surface_id) .get(&surface_id)
.and_then(|id| self.text_input_ids.get(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<M: From<Message> + Send + 'static> Common<M> {
Message::Prompt(prompt, secret, value_opt) => { Message::Prompt(prompt, secret, value_opt) => {
let prompt_was_none = self.prompt_opt.is_none(); let prompt_was_none = self.prompt_opt.is_none();
self.prompt_opt = Some((prompt, secret, value_opt)); self.prompt_opt = Some((prompt, secret, value_opt));
if prompt_was_none { if prompt_was_none
if let Some(surface_id) = self.active_surface_id_opt { && let Some(surface_id) = self.active_surface_id_opt
if let Some(text_input_id) = self && let Some(text_input_id) = self
.surface_names .surface_names
.get(&surface_id) .get(&surface_id)
.and_then(|id| self.text_input_ids.get(id)) .and_then(|id| self.text_input_ids.get(id))
{ {
tracing::info!("focus surface found id {:?}", text_input_id); tracing::info!("focus surface found id {:?}", text_input_id);
return widget::text_input::focus(text_input_id.clone()); return widget::text_input::focus(text_input_id.clone());
}
}
} }
} }
Message::SessionLockEvent(lock_event) => { Message::SessionLockEvent(lock_event) => {

View file

@ -482,7 +482,7 @@ impl App {
.discard() .discard()
} }
fn menu(&self, id: SurfaceId) -> Element<Message> { fn menu(&self, id: SurfaceId) -> Element<'_, Message> {
let window_width = self let window_width = self
.common .common
.window_size .window_size
@ -1884,12 +1884,12 @@ impl cosmic::Application for App {
} }
// Not used for layer surface window // Not used for layer surface window
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
unimplemented!() unimplemented!()
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view_window(&self, surface_id: SurfaceId) -> Element<Self::Message> { fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> {
let img = self let img = self
.common .common
.surface_images .surface_images

View file

@ -325,7 +325,7 @@ pub struct App {
} }
impl App { impl App {
fn menu(&self, surface_id: SurfaceId) -> Element<Message> { fn menu(&self, surface_id: SurfaceId) -> Element<'_, Message> {
let window_width = self let window_width = self
.common .common
.window_size .window_size
@ -1132,10 +1132,10 @@ impl cosmic::Application for App {
} }
self.spinner_rotation = 0.0; self.spinner_rotation = 0.0;
// Try to create lockfile when locking // Try to create lockfile when locking
if let Some(ref lockfile) = self.flags.lockfile_opt { if let Some(ref lockfile) = self.flags.lockfile_opt
if let Err(err) = fs::File::create(lockfile) { && let Err(err) = fs::File::create(lockfile)
tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err); {
} tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err);
} }
// Tell compositor to lock // Tell compositor to lock
return lock(); return lock();
@ -1165,10 +1165,10 @@ impl cosmic::Application for App {
} }
self.spinner_rotation = 0.0; self.spinner_rotation = 0.0;
// Try to delete lockfile when unlocking // Try to delete lockfile when unlocking
if let Some(ref lockfile) = self.flags.lockfile_opt { if let Some(ref lockfile) = self.flags.lockfile_opt
if let Err(err) = fs::remove_file(lockfile) { && let Err(err) = fs::remove_file(lockfile)
tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err); {
} tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err);
} }
// Destroy lock surfaces // Destroy lock surfaces
@ -1204,12 +1204,12 @@ impl cosmic::Application for App {
} }
// Not used for layer surface window // Not used for layer surface window
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
unimplemented!() unimplemented!()
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view_window(&self, surface_id: SurfaceId) -> Element<Self::Message> { fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> {
let img = self let img = self
.common .common
.surface_images .surface_images

View file

@ -77,16 +77,16 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<&'static str>>) -> Result<
}; };
} }
Some(SpecificDevice::Wireless(wireless)) => { Some(SpecificDevice::Wireless(wireless)) => {
if let Ok(ap) = wireless.active_access_point().await { if let Ok(ap) = wireless.active_access_point().await
if let Ok(strength) = ap.strength().await { && let Ok(strength) = ap.strength().await
// Wireless always overrides with the highest strength {
icon = match icon { // Wireless always overrides with the highest strength
NetworkIcon::Wireless(other_strength) => { icon = match icon {
NetworkIcon::Wireless(cmp::max(strength, other_strength)) NetworkIcon::Wireless(other_strength) => {
} NetworkIcon::Wireless(cmp::max(strength, other_strength))
_ => NetworkIcon::Wireless(strength), }
}; _ => NetworkIcon::Wireless(strength),
} };
} }
} }
_ => {} _ => {}

View file

@ -41,10 +41,10 @@ impl Time {
} }
// Try language-only fallback (e.g., "en" from "en-US") // Try language-only fallback (e.g., "en" from "en-US")
if let Some(lang) = cleaned_locale.split('-').next() { if let Some(lang) = cleaned_locale.split('-').next()
if let Ok(locale) = Locale::try_from_str(lang) { && let Ok(locale) = Locale::try_from_str(lang)
return locale; {
} return locale;
} }
} }
} }
@ -72,7 +72,7 @@ impl Time {
.timezone .timezone
.as_ref() .as_ref()
.map(|tz| jiff::Timestamp::now().to_zoned(tz.clone())) .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 { pub fn format_date(&self) -> String {

View file

@ -52,26 +52,26 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<(f64, bool, bool)>>) -> Re
loop { loop {
let mut info_opt = None; let mut info_opt = None;
if let Ok(mut percent) = dev.percentage().await { if let Ok(mut percent) = dev.percentage().await
if let Ok(state) = dev.state().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.); let threshold_enabled = dev.charge_threshold_enabled().await.unwrap_or_default();
if capacity <= 1. { let mut capacity = dev.capacity().await.unwrap_or(100.);
capacity = 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,
));
} }
// 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(); msg_tx.send(info_opt).await.unwrap();