From 1eb345085dc12a55b764182a5fc9401582978875 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 31 Dec 2025 11:45:31 -0500 Subject: [PATCH] chore: clippy --- cosmic-settings/src/app.rs | 10 +- .../src/pages/accessibility/magnifier.rs | 2 +- .../pages/applications/legacy_applications.rs | 2 +- .../src/pages/desktop/appearance/mod.rs | 5 +- .../src/pages/desktop/panel/applets_inner.rs | 4 +- .../src/pages/desktop/panel/inner.rs | 4 +- .../src/pages/desktop/window_management.rs | 2 +- cosmic-settings/src/pages/display/mod.rs | 7 +- .../src/pages/networking/vpn/mod.rs | 6 +- cosmic-settings/src/pages/networking/wifi.rs | 2 +- cosmic-settings/src/pages/networking/wired.rs | 1 + cosmic-settings/src/pages/sound/mod.rs | 10 +- cosmic-settings/src/pages/system/info.rs | 145 +++++++++--------- subscriptions/sound/src/lib.rs | 37 ++--- 14 files changed, 113 insertions(+), 124 deletions(-) diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index a830129..05173f9 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -164,9 +164,9 @@ pub enum Message { Page(page::Entity), PageMessage(crate::pages::Message), #[cfg(feature = "wayland")] - PanelConfig(CosmicPanelConfig), + PanelConfig(Box), #[cfg(any(feature = "page-window-management", feature = "page-accessibility"))] - CompConfig(CosmicCompConfig), + CompConfig(Box), SearchActivate, SearchChanged(String), SearchClear, @@ -333,7 +333,7 @@ impl cosmic::Application for SettingsApp { tracing::error!(?why, "panel config load error"); } - Message::PanelConfig(update.config) + Message::PanelConfig(Box::new(update.config)) }), // TODO: This should only be active when the dock page is active. #[cfg(feature = "wayland")] @@ -344,7 +344,7 @@ impl cosmic::Application for SettingsApp { tracing::error!(?why, "dock config load error"); } - Message::PanelConfig(update.config) + Message::PanelConfig(Box::new(update.config)) }), page.subscription(self.core()).map(Message::PageMessage), #[cfg(any(feature = "page-window-management", feature = "page-accessibility"))] @@ -355,7 +355,7 @@ impl cosmic::Application for SettingsApp { tracing::error!(?why, "comp config load error"); } - Message::CompConfig(update.config) + Message::CompConfig(Box::new(update.config)) }), ]; diff --git a/cosmic-settings/src/pages/accessibility/magnifier.rs b/cosmic-settings/src/pages/accessibility/magnifier.rs index a6ca4b9..2ba99a0 100644 --- a/cosmic-settings/src/pages/accessibility/magnifier.rs +++ b/cosmic-settings/src/pages/accessibility/magnifier.rs @@ -38,7 +38,7 @@ pub struct Page { #[derive(Debug, Clone)] pub enum Message { Event(wayland::AccessibilityEvent), - CompConfigUpdate(cosmic_comp_config::CosmicCompConfig), + CompConfigUpdate(Box), ProtocolUnavailable, SetMagnifier(bool), SetMouseShortcuts(bool), diff --git a/cosmic-settings/src/pages/applications/legacy_applications.rs b/cosmic-settings/src/pages/applications/legacy_applications.rs index 1d97bde..9cab593 100644 --- a/cosmic-settings/src/pages/applications/legacy_applications.rs +++ b/cosmic-settings/src/pages/applications/legacy_applications.rs @@ -112,7 +112,7 @@ impl page::Page for Page { tasks.push(cosmic::task::future(on_enter())); let refresh_pending = self.refresh_pending.clone(); - let (tx, mut rx) = cosmic_randr::channel(); + let (tx, rx) = cosmic_randr::channel(); let (canceller, cancelled) = oneshot::channel::<()>(); let runtime = tokio::runtime::Handle::current(); diff --git a/cosmic-settings/src/pages/desktop/appearance/mod.rs b/cosmic-settings/src/pages/desktop/appearance/mod.rs index cd896dc..b3f84cd 100644 --- a/cosmic-settings/src/pages/desktop/appearance/mod.rs +++ b/cosmic-settings/src/pages/desktop/appearance/mod.rs @@ -597,8 +597,8 @@ impl Page { (panel_config.name == "Dock").then_some(panel_config) }); - if let Some(dock_config_helper) = dock_config_helper.as_ref() { - if let Some(dock_config) = dock_config.as_mut() { + if let Some(dock_config_helper) = dock_config_helper.as_ref() + && let Some(dock_config) = dock_config.as_mut() { let padding = match roundness { Roundness::Round => 4, Roundness::SlightlyRound => 4, @@ -609,7 +609,6 @@ impl Page { tracing::error!(?why, "Error updating dock padding"); } } - } } // TODO: cache panel and dock configs so that they needn't be re-read diff --git a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs index 1de8837..e131302 100644 --- a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs @@ -170,7 +170,7 @@ pub enum Message { ReorderCenter(Vec>), ReorderEnd(Vec>), Applets(Vec>), - PanelConfig(CosmicPanelConfig), + PanelConfig(Box), StartDnd(Applet<'static>), // DnDTask(Arc ActionInner>>), Search(String), @@ -297,7 +297,7 @@ impl Page { pub fn update(&mut self, message: Message) -> Task { match message { Message::PanelConfig(c) => { - self.current_config = Some(c); + self.current_config = Some(*c); } Message::ReorderStart(start_list) => { diff --git a/cosmic-settings/src/pages/desktop/panel/inner.rs b/cosmic-settings/src/pages/desktop/panel/inner.rs index 10ac9fb..446ec1d 100644 --- a/cosmic-settings/src/pages/desktop/panel/inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/inner.rs @@ -433,7 +433,7 @@ pub enum Message { OpacityApply, OutputAdded(String, WlOutput), OutputRemoved(WlOutput), - PanelConfig(CosmicPanelConfig), + PanelConfig(Box), ResetPanel, FullReset, Surface(surface::Action), @@ -668,7 +668,7 @@ impl PageInner { } } Message::PanelConfig(c) => { - self.panel_config = Some(c); + self.panel_config = Some(*c); return Task::none(); } Message::ResetPanel | Message::FullReset => {} diff --git a/cosmic-settings/src/pages/desktop/window_management.rs b/cosmic-settings/src/pages/desktop/window_management.rs index f7c355e..7ab58c1 100644 --- a/cosmic-settings/src/pages/desktop/window_management.rs +++ b/cosmic-settings/src/pages/desktop/window_management.rs @@ -20,7 +20,7 @@ use tracing::error; #[derive(Clone, Debug)] pub enum Message { SuperKey(usize), - CompConfigUpdate(CosmicCompConfig), + CompConfigUpdate(Box), SetFocusFollowsCursor(bool), SaveFocusFollowsCursorDelay(bool), SetFocusFollowsCursorDelay(String), diff --git a/cosmic-settings/src/pages/display/mod.rs b/cosmic-settings/src/pages/display/mod.rs index 9101251..c648077 100644 --- a/cosmic-settings/src/pages/display/mod.rs +++ b/cosmic-settings/src/pages/display/mod.rs @@ -262,7 +262,7 @@ impl page::Page for Page { #[cfg(feature = "wayland")] { let refreshing_page = self.refreshing_page.clone(); - let (tx, mut rx) = cosmic_randr::channel(); + let (tx, rx) = cosmic_randr::channel(); let (canceller, cancelled) = oneshot::channel::<()>(); let runtime = tokio::runtime::Handle::current(); @@ -555,15 +555,14 @@ impl Page { return self.toggle_display(true); } - if let Some(v) = self.mirror_map.get(k) { - if v.equivalent(&self.active_display) { + if let Some(v) = self.mirror_map.get(k) + && v.equivalent(&self.active_display) { if let Some(output) = self.list.outputs.get(k) { return self.exec_randr(output, Randr::Toggle(true)); } else { return Task::none(); } } - } } return Task::none(); diff --git a/cosmic-settings/src/pages/networking/vpn/mod.rs b/cosmic-settings/src/pages/networking/vpn/mod.rs index 589528b..f8a9997 100644 --- a/cosmic-settings/src/pages/networking/vpn/mod.rs +++ b/cosmic-settings/src/pages/networking/vpn/mod.rs @@ -653,7 +653,7 @@ impl Page { ), ( "password".to_string(), - password.clone().into(), + password.clone(), ), ]), applied_tx, @@ -733,7 +733,7 @@ impl Page { secrets: HashMap::from_iter([ // username and password ("username".to_string(), username.clone().into()), - ("password".to_string(), password.clone().into()), + ("password".to_string(), password.clone()), ]), applied_tx, }) @@ -793,7 +793,7 @@ impl Page { id: name.clone(), uuid: Arc::from(""), username: None, - description: description, + description, password: previous, password_hidden: true, tx, diff --git a/cosmic-settings/src/pages/networking/wifi.rs b/cosmic-settings/src/pages/networking/wifi.rs index 9e6f89f..fb21b80 100644 --- a/cosmic-settings/src/pages/networking/wifi.rs +++ b/cosmic-settings/src/pages/networking/wifi.rs @@ -378,7 +378,7 @@ impl Page { self.connecting.remove(ssid.as_ref()); } else { self.dialog = Some(WiFiDialog::Password { - ssid: ssid.into(), + ssid, identity: matches!(network_type, NetworkType::EAP) .then(String::new), hw_address, diff --git a/cosmic-settings/src/pages/networking/wired.rs b/cosmic-settings/src/pages/networking/wired.rs index 2b569eb..eb29cd3 100644 --- a/cosmic-settings/src/pages/networking/wired.rs +++ b/cosmic-settings/src/pages/networking/wired.rs @@ -447,6 +447,7 @@ impl Page { } } + #[allow(clippy::too_many_arguments)] fn device_view<'a>( &'a self, spacing: cosmic::cosmic_theme::Spacing, diff --git a/cosmic-settings/src/pages/sound/mod.rs b/cosmic-settings/src/pages/sound/mod.rs index e6df57b..5c0b61b 100644 --- a/cosmic-settings/src/pages/sound/mod.rs +++ b/cosmic-settings/src/pages/sound/mod.rs @@ -216,21 +216,19 @@ impl Page { Message::ToggleOverAmplificationSink(enabled) => { self.amplification_sink = enabled; - if let Some(config) = &self.sound_config { - if let Err(why) = config.set(AMPLIFICATION_SINK, enabled) { + if let Some(config) = &self.sound_config + && let Err(why) = config.set(AMPLIFICATION_SINK, enabled) { tracing::error!(?why, "Failed to save over amplification setting"); } - } } Message::ToggleOverAmplificationSource(enabled) => { self.amplification_source = enabled; - if let Some(config) = &self.sound_config { - if let Err(why) = config.set(AMPLIFICATION_SOURCE, enabled) { + if let Some(config) = &self.sound_config + && let Err(why) = config.set(AMPLIFICATION_SOURCE, enabled) { tracing::error!(?why, "Failed to save over amplification setting"); } - } } Message::SetProfile(object_id, index) => { diff --git a/cosmic-settings/src/pages/system/info.rs b/cosmic-settings/src/pages/system/info.rs index 2adf419..a1158ff 100644 --- a/cosmic-settings/src/pages/system/info.rs +++ b/cosmic-settings/src/pages/system/info.rs @@ -22,13 +22,14 @@ pub struct Info { impl Info { pub fn load() -> Info { - let mut info = Info::default(); - - info.os_architecture = architecture(); - info.kernel_version = kernel_version(); - info.hardware_model = hardware_model(); - info.operating_system = operating_system(); - info.processor = processor_name(); + let mut info = Info { + os_architecture: architecture(), + kernel_version: kernel_version(), + hardware_model: hardware_model(), + operating_system: operating_system(), + processor: processor_name(), + ..Default::default() + }; let mut sys = sysinfo::System::new(); let disks = sysinfo::Disks::new_with_refreshed_list(); @@ -194,7 +195,7 @@ fn hardware_model() -> String { const DMI_DIR: &str = "/sys/devices/virtual/dmi/id/"; const VERSION_IGNORING_PRODUCTS: &[&str] = &["Dev One"]; - let sys_vendor = read_to_string(&format!("{DMI_DIR}sys_vendor")) + let sys_vendor = read_to_string(format!("{DMI_DIR}sys_vendor")) .map(|s| s.trim().to_string()) .unwrap_or_default(); @@ -206,25 +207,25 @@ fn hardware_model() -> String { let mut model = sys_vendor.clone(); if let Some(mut name) = - read_to_string(&format!("{DMI_DIR}board_name")).map(|s| s.trim().to_string()) + read_to_string(format!("{DMI_DIR}board_name")).map(|s| s.trim().to_string()) + && !name.is_empty() + && name != sys_vendor { - if !name.is_empty() && name != sys_vendor { - // Ensure that the name does not contain the vendor - name = name - .strip_prefix(&sys_vendor) - .map(|s| s.trim().to_string()) - .unwrap_or(name); + // Ensure that the name does not contain the vendor + name = name + .strip_prefix(&sys_vendor) + .map(|s| s.trim().to_string()) + .unwrap_or(name); - model.push(' '); - model.push_str(&name); + model.push(' '); + model.push_str(&name); - if let Some(version) = - read_to_string(&format!("{DMI_DIR}board_version")).map(|s| s.trim().to_string()) - { - if !version.is_empty() && !VERSION_IGNORING_PRODUCTS.contains(&name.as_str()) { - model.push_str(&format!(" ({version})")); - } - } + if let Some(version) = + read_to_string(format!("{DMI_DIR}board_version")).map(|s| s.trim().to_string()) + && !version.is_empty() + && !VERSION_IGNORING_PRODUCTS.contains(&name.as_str()) + { + model.push_str(&format!(" ({version})")); } } @@ -315,46 +316,42 @@ fn get_all_lspci_gpus() -> Vec<(u32, u32, String)> { // Parse device ID from format: "00:02.0 VGA compatible controller [0300]: Intel Corporation HD Graphics 500 [8086:5a85] (rev 0b)" // We want to extract vendor:device IDs (8086:5a85) and the name (Intel Corporation HD Graphics 500) - if let Some(ids_start) = line.rfind('[') { - if let Some(ids_end) = line.rfind(']') { - let ids = &line[ids_start + 1..ids_end]; + if let Some(ids_start) = line.rfind('[') + && let Some(ids_end) = line.rfind(']') + { + let ids = &line[ids_start + 1..ids_end]; - if let Some(colon_pos) = ids.find(':') { - let vendor_id_str = &ids[..colon_pos]; - let device_id_str = &ids[colon_pos + 1..]; + if let Some(colon_pos) = ids.find(':') { + let vendor_id_str = &ids[..colon_pos]; + let device_id_str = &ids[colon_pos + 1..]; - if let (Ok(vendor_id), Ok(device_id)) = ( - u32::from_str_radix(vendor_id_str, 16), - u32::from_str_radix(device_id_str, 16), - ) { - if let Some(name_start) = line.find(": ") { - let full_name = line[name_start + 2..ids_start].trim(); + if let (Ok(vendor_id), Ok(device_id)) = ( + u32::from_str_radix(vendor_id_str, 16), + u32::from_str_radix(device_id_str, 16), + ) && let Some(name_start) = line.find(": ") + { + let full_name = line[name_start + 2..ids_start].trim(); - // Look for marketing name in brackets like "GP108M [GeForce MX150]" - // We prefer the marketing name over the chip code - let gpu_name = if let Some(bracket_start) = full_name.find('[') { - if let Some(bracket_end) = full_name.find(']') { - let vendor_part = full_name[..bracket_start].trim(); - let marketing_name = - full_name[bracket_start + 1..bracket_end].trim(); + // Look for marketing name in brackets like "GP108M [GeForce MX150]" + // We prefer the marketing name over the chip code + let gpu_name = if let Some(bracket_start) = full_name.find('[') { + if let Some(bracket_end) = full_name.find(']') { + let vendor_part = full_name[..bracket_start].trim(); + let marketing_name = full_name[bracket_start + 1..bracket_end].trim(); - let vendor = vendor_part - .split_whitespace() - .next() - .unwrap_or(vendor_part); + let vendor = + vendor_part.split_whitespace().next().unwrap_or(vendor_part); - format!("{} {}", vendor, marketing_name) - } else { - full_name.to_string() - } - } else { - full_name.to_string() - }; - - if !gpu_name.is_empty() { - gpus.push((vendor_id, device_id, gpu_name)); - } + format!("{} {}", vendor, marketing_name) + } else { + full_name.to_string() } + } else { + full_name.to_string() + }; + + if !gpu_name.is_empty() { + gpus.push((vendor_id, device_id, gpu_name)); } } } @@ -393,23 +390,23 @@ fn get_lspci_gpu_names() -> HashMap { // Or with marketing name: "00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P GT2 [Iris Xe Graphics] [8086:46a6] (rev 0c)" // We want to extract the device ID (5a85/46a6) and the name, preferring marketing name if available - if let Some(ids_start) = line.rfind('[') { - if let Some(ids_end) = line.rfind(']') { - let ids = &line[ids_start + 1..ids_end]; + if let Some(ids_start) = line.rfind('[') + && let Some(ids_end) = line.rfind(']') + { + let ids = &line[ids_start + 1..ids_end]; - // Parse vendor:device format like "8086:5a85" - if let Some(colon_pos) = ids.find(':') { - let device_id_str = &ids[colon_pos + 1..]; - if let Ok(device_id) = u32::from_str_radix(device_id_str, 16) { - // Extract the GPU name between ": " and the last "[" - if let Some(name_start) = line.find(": ") { - let full_name = line[name_start + 2..ids_start].trim(); - let gpu_name = full_name - .replace(" Corporation", "") - .replace(" [Intel Graphics]", ""); - if !gpu_name.is_empty() { - gpu_map.insert(device_id, gpu_name); - } + // Parse vendor:device format like "8086:5a85" + if let Some(colon_pos) = ids.find(':') { + let device_id_str = &ids[colon_pos + 1..]; + if let Ok(device_id) = u32::from_str_radix(device_id_str, 16) { + // Extract the GPU name between ": " and the last "[" + if let Some(name_start) = line.find(": ") { + let full_name = line[name_start + 2..ids_start].trim(); + let gpu_name = full_name + .replace(" Corporation", "") + .replace(" [Intel Graphics]", ""); + if !gpu_name.is_empty() { + gpu_map.insert(device_id, gpu_name); } } } diff --git a/subscriptions/sound/src/lib.rs b/subscriptions/sound/src/lib.rs index 58cd094..e129c59 100644 --- a/subscriptions/sound/src/lib.rs +++ b/subscriptions/sound/src/lib.rs @@ -26,16 +26,13 @@ pub fn watch() -> impl Stream + MaybeSend + 'static { let receiver = sender.clone(); _ = emitter - .send( - Message::SubHandle(Arc::new(SubscriptionHandle { - cancel_tx, - pipewire: pipewire::run(move |event| { - sender.0.lock().unwrap().push(event); - sender.1.notify_one(); - }), - })) - .into(), - ) + .send(Message::SubHandle(Arc::new(SubscriptionHandle { + cancel_tx, + pipewire: pipewire::run(move |event| { + sender.0.lock().unwrap().push(event); + sender.1.notify_one(); + }), + }))) .await; let forwarder = Box::pin(async { @@ -215,7 +212,7 @@ impl Model { self.sink_volume_debounce = true; return cosmic::Task::future(async move { tokio::time::sleep(Duration::from_millis(128)).await; - Message::SinkVolumeApply(id).into() + Message::SinkVolumeApply(id) }); } @@ -253,10 +250,8 @@ impl Model { } None - } else if let Some(name) = self.node_names.get(node_id) { - Some(name.clone()) } else { - None + self.node_names.get(node_id).map(|name| name.clone()) }; tokio::task::spawn(async move { @@ -294,7 +289,7 @@ impl Model { self.sink_volume_debounce = true; return cosmic::Task::future(async move { tokio::time::sleep(Duration::from_millis(128)).await; - Message::SinkVolumeApply(node_id).into() + Message::SinkVolumeApply(node_id) }); } @@ -373,7 +368,7 @@ impl Model { self.source_volume_debounce = true; return cosmic::Task::future(async move { tokio::time::sleep(Duration::from_millis(128)).await; - Message::SourceVolumeApply(node_id).into() + Message::SourceVolumeApply(node_id) }); } @@ -510,12 +505,12 @@ impl Model { fn(&mut Self, NodeId), ) = match route.direction { pipewire::Direction::Output => ( - self.active_sink_device.clone(), + self.active_sink_device, &self.sink_node_ids, Self::set_default_sink_id, ), pipewire::Direction::Input => ( - self.active_source_device.clone(), + self.active_source_device, &self.source_node_ids, Self::set_default_source_id, ), @@ -685,7 +680,7 @@ impl Model { if routes.len() < index as usize + 1 { let additional = (index as usize + 1) - routes.capacity(); routes.reserve_exact(additional); - routes.extend(std::iter::repeat(pipewire::Route::default()).take(additional)); + routes.extend(std::iter::repeat_n(pipewire::Route::default(), additional)); } routes[index as usize] = route; } @@ -815,7 +810,7 @@ impl Model { let (active_profile, indexes, descriptions) = self .active_profiles .get(device_id) - .and_then(|profile| { + .map(|profile| { let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles .iter() .filter(|p| { @@ -835,7 +830,7 @@ impl Model { .find(|(_, p)| p.index == profile.index) .map(|(pos, _)| pos); - Some((pos, indexes, descriptions)) + (pos, indexes, descriptions) }) .unwrap_or_else(|| { let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles