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,10 +86,10 @@ 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?
BgSource::Path(path) => { if let BgSource::Path(path) = source
if !self.bg_path_data.contains_key(path) { && !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);
@ -94,10 +100,6 @@ impl UserData {
} }
} }
} }
// Other types not supported
_ => {}
}
}
} }
pub fn load_config_as_user(&mut self) { pub fn load_config_as_user(&mut self) {

View file

@ -204,8 +204,9 @@ 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(); self.active_layouts.clear();
let config_layouts = xkb_config.layout.split_terminator(','); let config_layouts = xkb_config.layout.split_terminator(',');
let config_variants = xkb_config let config_variants = xkb_config
@ -247,7 +248,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
tracing::info!("{:?}", self.active_layouts); tracing::info!("{:?}", self.active_layouts);
} }
} }
}
pub fn update(&mut self, message: Message) -> Task<M> { pub fn update(&mut self, message: Message) -> Task<M> {
match message { match message {
@ -271,14 +271,14 @@ 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))
@ -287,7 +287,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
} }
} }
} }
}
Message::NetworkIcon(network_icon_opt) => { Message::NetworkIcon(network_icon_opt) => {
self.network_icon_opt = self.network_icon_opt =
network_icon_opt.map(|name| widget::icon::from_name(name).into()); network_icon_opt.map(|name| widget::icon::from_name(name).into());
@ -306,9 +305,9 @@ 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))
@ -317,8 +316,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
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) => {
if let Some(on_session_lock_event) = &self.on_session_lock_event { if let Some(on_session_lock_event) = &self.on_session_lock_event {
return Task::done(cosmic::Action::App(on_session_lock_event(lock_event))); return Task::done(cosmic::Action::App(on_session_lock_event(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,11 +1132,11 @@ 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,11 +1165,11 @@ 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
let mut commands = Vec::with_capacity(self.common.surface_ids.len() + 1); let mut commands = Vec::with_capacity(self.common.surface_ids.len() + 1);
@ -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,8 +77,9 @@ 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 // Wireless always overrides with the highest strength
icon = match icon { icon = match icon {
NetworkIcon::Wireless(other_strength) => { NetworkIcon::Wireless(other_strength) => {
@ -88,7 +89,6 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<&'static str>>) -> Result<
}; };
} }
} }
}
_ => {} _ => {}
} }
} }

View file

@ -41,13 +41,13 @@ 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;
} }
} }
} }
}
tracing::warn!("No valid locale found in environment, using fallback"); tracing::warn!("No valid locale found in environment, using fallback");
Locale::try_from_str("en-US").expect("Failed to parse fallback locale 'en-US'") Locale::try_from_str("en-US").expect("Failed to parse fallback locale 'en-US'")
} }
@ -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,8 +52,9 @@ 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 threshold_enabled = dev.charge_threshold_enabled().await.unwrap_or_default();
let mut capacity = dev.capacity().await.unwrap_or(100.); let mut capacity = dev.capacity().await.unwrap_or(100.);
if capacity <= 1. { if capacity <= 1. {
@ -72,7 +73,6 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<(f64, bool, bool)>>) -> Re
threshold_enabled, threshold_enabled,
)); ));
} }
}
msg_tx.send(info_opt).await.unwrap(); msg_tx.send(info_opt).await.unwrap();