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,
}
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
_ => {}
}
}
}

View file

@ -204,48 +204,48 @@ impl<M: From<Message> + Send + 'static> Common<M> {
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<M: From<Message> + Send + 'static> Common<M> {
&& !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<M: From<Message> + Send + 'static> Common<M> {
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) => {

View file

@ -482,7 +482,7 @@ impl App {
.discard()
}
fn menu(&self, id: SurfaceId) -> Element<Message> {
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<Self::Message> {
fn view(&self) -> Element<'_, Self::Message> {
unimplemented!()
}
/// 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
.common
.surface_images

View file

@ -325,7 +325,7 @@ pub struct App {
}
impl App {
fn menu(&self, surface_id: SurfaceId) -> Element<Message> {
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<Self::Message> {
fn view(&self) -> Element<'_, Self::Message> {
unimplemented!()
}
/// 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
.common
.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)) => {
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),
};
}
}
_ => {}

View file

@ -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 {

View file

@ -52,26 +52,26 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<(f64, bool, bool)>>) -> 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();