From 787c5ed49f072ac84865a107e81b9738518a2a66 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: Thu, 19 Feb 2026 18:33:47 +0100 Subject: [PATCH] chore: clippy --- .../src/pages/desktop/appearance/commands.rs | 16 +- .../src/pages/desktop/appearance/mod.rs | 2 +- .../pages/input/keyboard/shortcuts/custom.rs | 2 +- .../src/pages/networking/vpn/mod.rs | 2 +- cosmic-settings/src/pages/networking/wifi.rs | 7 +- crates/cosmic-pipewire/src/lib.rs | 41 ++-- crates/cosmic-pipewire/src/spa_utils.rs | 6 +- pages/wallpapers/src/lib.rs | 38 ++-- subscriptions/accessibility/src/lib.rs | 8 +- .../network-manager/src/available_wifi.rs | 21 ++- .../network-manager/src/hw_address.rs | 4 +- subscriptions/network-manager/src/lib.rs | 98 +++++----- .../network-manager/src/nm_secret_agent.rs | 178 ++++++++---------- subscriptions/sound/src/lib.rs | 38 ++-- 14 files changed, 218 insertions(+), 243 deletions(-) diff --git a/cosmic-settings/src/pages/desktop/appearance/commands.rs b/cosmic-settings/src/pages/desktop/appearance/commands.rs index c181417..aa2a680 100644 --- a/cosmic-settings/src/pages/desktop/appearance/commands.rs +++ b/cosmic-settings/src/pages/desktop/appearance/commands.rs @@ -41,14 +41,14 @@ pub fn import_theme(path: &Path) -> color_eyre::Result<()> { let mut manager = Manager::default(); - if manager.mode().is_dark != is_dark { - if let Err(err) = manager.dark_mode(is_dark) { - return Err(color_eyre::eyre::eyre!( - "Failed to set {} mode: {:?}", - mode_str, - err - )); - } + if manager.mode().is_dark != is_dark + && let Err(err) = manager.dark_mode(is_dark) + { + return Err(color_eyre::eyre::eyre!( + "Failed to set {} mode: {:?}", + mode_str, + err + )); } manager diff --git a/cosmic-settings/src/pages/desktop/appearance/mod.rs b/cosmic-settings/src/pages/desktop/appearance/mod.rs index cac3087..855b4b5 100644 --- a/cosmic-settings/src/pages/desktop/appearance/mod.rs +++ b/cosmic-settings/src/pages/desktop/appearance/mod.rs @@ -536,7 +536,7 @@ impl Page { Message::Daytime(day_time) => { self.day_time = day_time; return Task::none(); - }, + } Message::ThemeModeUpdate(mode) => { let was_dark = self.theme_manager.mode().is_dark; diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs index c6f9d97..fe8872b 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs @@ -189,7 +189,7 @@ impl Page { } Message::ReplaceApply => { - if let Some((mut binding, ..)) = self.replace_dialog.pop() { + if let Some((binding, ..)) = self.replace_dialog.pop() { self.add_shortcut(binding, true); if self.replace_dialog.is_empty() { diff --git a/cosmic-settings/src/pages/networking/vpn/mod.rs b/cosmic-settings/src/pages/networking/vpn/mod.rs index 75f446a..16ccbe8 100644 --- a/cosmic-settings/src/pages/networking/vpn/mod.rs +++ b/cosmic-settings/src/pages/networking/vpn/mod.rs @@ -846,7 +846,7 @@ impl Page { ) .collect() .then(|id| { - if id.get(0).is_some_and(|id| *id == SECURE_INPUT_VPN.clone()) { + if id.first().is_some_and(|id| *id == SECURE_INPUT_VPN.clone()) { Task::none() } else { focus(SECURE_INPUT_VPN.clone()) diff --git a/cosmic-settings/src/pages/networking/wifi.rs b/cosmic-settings/src/pages/networking/wifi.rs index 207d637..6239e9b 100644 --- a/cosmic-settings/src/pages/networking/wifi.rs +++ b/cosmic-settings/src/pages/networking/wifi.rs @@ -371,7 +371,7 @@ impl Page { ssid, network_type, _tx, - interface, + _interface, ) => { if success || matches!(network_type, NetworkType::Open) { self.connecting.remove(ssid.as_ref()); @@ -747,7 +747,10 @@ impl Page { ) .collect() .then(|id| { - if id.get(0).is_some_and(|id| *id == SECURE_INPUT_WIFI.clone()) { + if id + .first() + .is_some_and(|id| *id == SECURE_INPUT_WIFI.clone()) + { Task::none() } else { focus(SECURE_INPUT_WIFI.clone()) diff --git a/crates/cosmic-pipewire/src/lib.rs b/crates/cosmic-pipewire/src/lib.rs index d9e5dac..3aefd1e 100644 --- a/crates/cosmic-pipewire/src/lib.rs +++ b/crates/cosmic-pipewire/src/lib.rs @@ -34,7 +34,7 @@ use pipewire::{ proxy::{ProxyListener, ProxyT}, types::ObjectType, }; -use std::{cell::RefCell, rc::Rc, u32}; +use std::{cell::RefCell, rc::Rc}; pub type NodeId = u32; pub type RouteId = u32; @@ -181,10 +181,10 @@ fn run_service( return; } - if let Some(device) = Device::from_device(info) { - if let Some(state) = state.upgrade() { - state.borrow_mut().add_device(pw_id, device); - } + if let Some(device) = Device::from_device(info) + && let Some(state) = state.upgrade() + { + state.borrow_mut().add_device(pw_id, device); } } }) @@ -281,10 +281,10 @@ fn run_service( .info({ let state = Rc::downgrade(&state); move |info| { - if let Some(node) = Node::from_node(info) { - if let Some(state) = state.upgrade() { - state.borrow_mut().add_node(id, node); - } + if let Some(node) = Node::from_node(info) + && let Some(state) = state.upgrade() + { + state.borrow_mut().add_node(id, node); } } }) @@ -357,24 +357,18 @@ fn run_service( "default.audio.sink" => { if let Ok(value) = serde_json::de::from_str::(value) + && let Some(state) = state.upgrade() { - if let Some(state) = state.upgrade() { - state - .borrow_mut() - .default_sink(value.name.to_owned()) - } + state.borrow_mut().default_sink(value.name.to_owned()) } } "default.audio.source" => { if let Ok(value) = serde_json::de::from_str::(value) + && let Some(state) = state.upgrade() { - if let Some(state) = state.upgrade() { - state - .borrow_mut() - .default_source(value.name.to_owned()) - } + state.borrow_mut().default_source(value.name.to_owned()) } } @@ -530,7 +524,7 @@ impl State { if routes.len() < index as usize + 1 { let additional = (index as usize + 1) - routes.capacity(); routes.reserve_exact(additional); - routes.extend(std::iter::repeat(Route::default()).take(additional)); + routes.extend(std::iter::repeat_n(Route::default(), additional)); } routes[index as usize] = route.clone(); @@ -586,7 +580,7 @@ impl State { if routes.len() < index as usize + 1 { let additional = (index as usize + 1) - routes.capacity(); routes.reserve_exact(additional); - routes.extend(std::iter::repeat(Route::default()).take(additional)); + routes.extend(std::iter::repeat_n(Route::default(), additional)); } routes[index as usize] = route.clone(); @@ -769,7 +763,6 @@ impl State { if let Some(param) = Pod::from_bytes(&serialized) { device.set_param(ParamType::Route, 0, param); } - return; } fn set_node_props(&mut self, id: NodeId, props: NodeProps) { @@ -817,7 +810,7 @@ impl State { FormatProperties(libspa_sys::SPA_PROP_channelVolumes), ValueArray, pod::ValueArray::Float(volume::to_channel_volumes( - &props.channel_map.as_deref().unwrap_or_default(), + props.channel_map.as_deref().unwrap_or_default(), volume, balance, )) @@ -887,7 +880,7 @@ impl State { ValueArray, pod::ValueArray::Float(if matches!(route.direction, Direction::Output) { volume::to_channel_volumes( - &props.channel_map.as_deref().unwrap_or_default(), + props.channel_map.as_deref().unwrap_or_default(), volume, balance, ) diff --git a/crates/cosmic-pipewire/src/spa_utils.rs b/crates/cosmic-pipewire/src/spa_utils.rs index 7e3e859..0593dfe 100644 --- a/crates/cosmic-pipewire/src/spa_utils.rs +++ b/crates/cosmic-pipewire/src/spa_utils.rs @@ -14,10 +14,8 @@ pub fn string_from_pod(pod: &Pod) -> Option { unsafe { // SAFETY: Pod is checked to be a string beforehand - if libspa_sys::spa_pod_get_string(pod.as_raw_ptr(), &mut cstr) == 0 { - if !cstr.is_null() { - return Some(String::from_utf8_lossy(CStr::from_ptr(cstr).to_bytes()).into_owned()); - } + if libspa_sys::spa_pod_get_string(pod.as_raw_ptr(), &mut cstr) == 0 && !cstr.is_null() { + return Some(String::from_utf8_lossy(CStr::from_ptr(cstr).to_bytes()).into_owned()); } } diff --git a/pages/wallpapers/src/lib.rs b/pages/wallpapers/src/lib.rs index fe7e338..498b424 100644 --- a/pages/wallpapers/src/lib.rs +++ b/pages/wallpapers/src/lib.rs @@ -210,29 +210,29 @@ fn load_thumbnail( cache_dir: Option<&Path>, path: &Path, ) -> Option { - if let Some(cache_dir) = cache_dir { - if let Ok(ctime) = path.metadata().and_then(|meta| meta.created()) { - // Search for thumbnail by a unique hash string. - let mut hasher = DefaultHasher::new(); - path.hash(&mut hasher); - ctime.hash(&mut hasher); - let hash = hasher.finish(); + if let Some(cache_dir) = cache_dir + && let Ok(ctime) = path.metadata().and_then(|meta| meta.created()) + { + // Search for thumbnail by a unique hash string. + let mut hasher = DefaultHasher::new(); + path.hash(&mut hasher); + ctime.hash(&mut hasher); + let hash = hasher.finish(); - let thumbnail_path = cache_dir.join(format!("{hash:x}.png")); + let thumbnail_path = cache_dir.join(format!("{hash:x}.png")); - if thumbnail_path.exists() { - if let Some(image) = open_image(input_buffer, &thumbnail_path) { - return Some(ImageOperation::Cached(image)); - } - - let _res = std::fs::remove_file(&thumbnail_path); + if thumbnail_path.exists() { + if let Some(image) = open_image(input_buffer, &thumbnail_path) { + return Some(ImageOperation::Cached(image)); } - return Some(ImageOperation::GenerateThumbnail { - path: Some(thumbnail_path), - image: open_image(input_buffer, path)?, - }); + let _res = std::fs::remove_file(&thumbnail_path); } + + return Some(ImageOperation::GenerateThumbnail { + path: Some(thumbnail_path), + image: open_image(input_buffer, path)?, + }); } if let Some(image) = open_image(input_buffer, path) { @@ -396,7 +396,7 @@ fn border_radius( p += (2 * x + 2) as i32; } else { // draw when moving to next pixel in y-direction - if y % 16 == 0 { + if y.is_multiple_of(16) { draw(img, alpha, x / 16, y / 16); draw(img, alpha, y / 16, x / 16); skip_draw = true; diff --git a/subscriptions/accessibility/src/lib.rs b/subscriptions/accessibility/src/lib.rs index e2ad484..e9a4627 100644 --- a/subscriptions/accessibility/src/lib.rs +++ b/subscriptions/accessibility/src/lib.rs @@ -57,10 +57,10 @@ impl State { }; let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); let mut enabled = false; - if let Ok(proxy) = StatusProxy::new(&conn).await { - if let Ok(status) = proxy.screen_reader_enabled().await { - enabled = status; - } + if let Ok(proxy) = StatusProxy::new(&conn).await + && let Ok(status) = proxy.screen_reader_enabled().await + { + enabled = status; } _ = output.send(Response::Init(enabled, tx)).await; Some(State { diff --git a/subscriptions/network-manager/src/available_wifi.rs b/subscriptions/network-manager/src/available_wifi.rs index 858f01d..f467092 100644 --- a/subscriptions/network-manager/src/available_wifi.rs +++ b/subscriptions/network-manager/src/available_wifi.rs @@ -21,11 +21,11 @@ pub async fn handle_wireless_device( let mut scan_changed = device.receive_last_scan_changed().await; - if let Some(t) = scan_changed.next().await { - if let Ok(-1) = t.get().await { - tracing::error!("wireless device scan errored"); - return Ok(Default::default()); - } + if let Some(t) = scan_changed.next().await + && let Ok(-1) = t.get().await + { + tracing::error!("wireless device scan errored"); + return Ok(Default::default()); } let access_points = device.get_access_points().await?; @@ -45,10 +45,10 @@ pub async fn handle_wireless_device( if let Some((ssid, strength)) = ssid_res.ok().zip(strength_res.ok()) { let ssid = String::from_utf8_lossy(&ssid.clone()).into_owned(); - if let Some(access_point) = aps.get(&ssid) { - if access_point.strength > strength { - continue; - } + if let Some(access_point) = aps.get(&ssid) + && access_point.strength > strength + { + continue; } let Ok(flags) = ap.rsn_flags().await else { @@ -56,7 +56,8 @@ pub async fn handle_wireless_device( }; let network_type = if flags.intersects(ApSecurityFlags::KEY_MGMT_802_1X) { NetworkType::EAP - } else if flags.intersects(ApSecurityFlags::KEY_MGMTPSK | ApSecurityFlags::KEY_MGMT_SAE) { + } else if flags.intersects(ApSecurityFlags::KEY_MGMTPSK | ApSecurityFlags::KEY_MGMT_SAE) + { NetworkType::PskOrSae } else if flags.intersects(ApSecurityFlags::KEY_MGMT_OWE) || flags.is_empty() { NetworkType::Open diff --git a/subscriptions/network-manager/src/hw_address.rs b/subscriptions/network-manager/src/hw_address.rs index 9803780..db29158 100644 --- a/subscriptions/network-manager/src/hw_address.rs +++ b/subscriptions/network-manager/src/hw_address.rs @@ -18,8 +18,8 @@ impl HwAddress { .ok() .map(|address| HwAddress { address }) } - pub fn from_string(arg: &String) -> Option { - HwAddress::from_str(arg.as_str()) + pub fn from_string(arg: &str) -> Option { + HwAddress::from_str(arg) } } diff --git a/subscriptions/network-manager/src/lib.rs b/subscriptions/network-manager/src/lib.rs index 48e5702..e1b6ca4 100644 --- a/subscriptions/network-manager/src/lib.rs +++ b/subscriptions/network-manager/src/lib.rs @@ -16,7 +16,6 @@ pub use cosmic_dbus_networkmanager as dbus; pub use dbus::settings::connection::Settings; use cosmic_dbus_networkmanager::{ - active_connection::ActiveConnection, device::SpecificDevice, interface::{ enums::{self, ActiveConnectionState, DeviceType, NmConnectivityState}, @@ -185,12 +184,11 @@ async fn start_listening( let mut changed = c.receive_state_changed().await; _ = tokio::time::timeout(Duration::from_secs(5), async move { loop { - if let Some(next) = changed.next().await { - if let Ok(ActiveConnectionState::Deactivated) = + if let Some(next) = changed.next().await + && let Ok(ActiveConnectionState::Deactivated) = next.get().await.map(ActiveConnectionState::from) - { - break; - } + { + break; } } }) @@ -222,12 +220,11 @@ async fn start_listening( let mut changed = c.receive_state_changed().await; _ = tokio::time::timeout(Duration::from_secs(5), async move { loop { - if let Some(next) = changed.next().await { - if let Ok(ActiveConnectionState::Deactivated) = + if let Some(next) = changed.next().await + && let Ok(ActiveConnectionState::Deactivated) = next.get().await.map(ActiveConnectionState::from) - { - break; - } + { + break; } } }) @@ -528,7 +525,8 @@ async fn start_listening( }) .await; } - }); + }) + .await; } else { let known_conns = s.list_connections().await.unwrap_or_default(); for c in known_conns { @@ -540,42 +538,41 @@ async fn start_listening( .clone() .and_then(|w| w.ssid) .and_then(|s| String::from_utf8(s).ok()) + && saved_ssid == ssid.as_ref() { - if saved_ssid == ssid.as_ref() { - let password = - c.get_secrets("802-11-wireless-security") - .await - .ok() - .and_then(|secrets| { - // Look for PSK password - secrets - .get("802-11-wireless-security") - .and_then(|sec| sec.get("psk")) - .and_then(|v| { - v.downcast_ref::().ok() - }) - .map(|s| s.to_string()) - .or_else(|| { - // Fallback to WEP key + let password = c + .get_secrets("802-11-wireless-security") + .await + .ok() + .and_then(|secrets| { + // Look for PSK password secrets .get("802-11-wireless-security") + .and_then(|sec| sec.get("psk")) + .and_then(|v| { + v.downcast_ref::().ok() + }) + .map(|s| s.to_string()) + .or_else(|| { + // Fallback to WEP key + secrets + .get("802-11-wireless-security") .and_then(|sec| sec.get("wep-key0")) .and_then(|v| { v.downcast_ref::().ok() }) .map(|s| s.to_string()) - }) - }); + }) + }); - _ = output - .send(Event::WiFiCredentials { - ssid: ssid.clone(), - password: password.map(SecureString::from), - security_type, - }) - .await; - break; - } + _ = output + .send(Event::WiFiCredentials { + ssid: ssid.clone(), + password: password.map(SecureString::from), + security_type, + }) + .await; + break; } } } @@ -616,10 +613,9 @@ async fn has_saved_wifi_credentials(conn: &zbus::Connection, ssid: &str) -> bool .wifi .and_then(|w| w.ssid) .and_then(|ssid| String::from_utf8(ssid).ok()) + && saved_ssid == ssid { - if saved_ssid == ssid { - return true; - } + return true; } } } @@ -983,11 +979,10 @@ impl NetworkManagerState { .clone() .and_then(|w| w.ssid) .and_then(|ssid| String::from_utf8(ssid).ok()) + && cur_ssid == ssid { - if cur_ssid == ssid { - known_conn = Some(c); - break; - } + known_conn = Some(c); + break; } } @@ -1014,9 +1009,9 @@ impl NetworkManagerState { .ok_or_else(|| Error::MissingField("uuid"))? .clone(), ) - .map_err(|err| zbus::Error::Variant(err))?; + .map_err(zbus::Error::Variant)?; - if let Some((pass, secret_tx)) = password.clone().zip(secret_tx.as_ref()) { + if let Some((pass, secret_tx)) = password.zip(secret_tx.as_ref()) { let pass = SecureString::from(pass); let (applied_tx, applied_rx) = tokio::sync::oneshot::channel(); @@ -1056,7 +1051,7 @@ impl NetworkManagerState { .ok_or_else(|| Error::MissingField("uuid"))? .clone(), ) - .map_err(|err| zbus::Error::Variant(err))?; + .map_err(zbus::Error::Variant)?; let (applied_tx, applied_rx) = tokio::sync::oneshot::channel(); let setting_name: String = if identity.is_some() { "802-1x".into() @@ -1081,8 +1076,7 @@ impl NetworkManagerState { } } - let active_conn = - ActiveConnection::from(nm.activate_connection(&known_conn, &device).await?); + let active_conn = nm.activate_connection(&known_conn, &device).await?; let mut changes = active_conn.receive_state_changed().await; _ = tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; let mut count = 5; @@ -1120,7 +1114,7 @@ impl NetworkManagerState { .ok_or_else(|| Error::MissingField("uuid"))? .clone(), ) - .map_err(|err| zbus::Error::Variant(err))?; + .map_err(zbus::Error::Variant)?; let (applied_tx, applied_rx) = tokio::sync::oneshot::channel(); let setting_name: String = if identity.is_some() { "802-1x".into() diff --git a/subscriptions/network-manager/src/nm_secret_agent.rs b/subscriptions/network-manager/src/nm_secret_agent.rs index f67b892..d79cb16 100644 --- a/subscriptions/network-manager/src/nm_secret_agent.rs +++ b/subscriptions/network-manager/src/nm_secret_agent.rs @@ -16,7 +16,7 @@ use zbus::{ pub type SecretSender = Arc>>>; -pub const SECRET_ID: &'static str = "com.system76.CosmicSettings.NetworkManager"; +pub const SECRET_ID: &str = "com.system76.CosmicSettings.NetworkManager"; pub const DBUS_PATH: &str = "/org/freedesktop/NetworkManager/SecretAgent"; bitflags! { @@ -151,10 +151,10 @@ async fn secret_agent_stream_impl( { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; - if collection.is_locked().await.map_err(|e| Arc::new(e))? { - _ = collection.unlock().await.map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; + if collection.is_locked().await.map_err(Arc::new)? { + collection.unlock().await.map_err(Arc::new)?; } } // register the secret agent with NetworkManager @@ -183,8 +183,8 @@ async fn secret_agent_stream_impl( } => { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; if secrets.is_empty() { let mut attributes = std::collections::HashMap::new(); @@ -193,10 +193,10 @@ async fn secret_agent_stream_impl( let search_items = collection .search_items(attributes) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; for item in &search_items { - item.delete().await.map_err(|e| Arc::new(e))?; + item.delete().await.map_err(Arc::new)?; } let _ = applied_tx.send(()); @@ -218,7 +218,7 @@ async fn secret_agent_stream_impl( "text/plain", ) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; } let _ = applied_tx.send(()); } @@ -229,8 +229,8 @@ async fn secret_agent_stream_impl( } => { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; let mut attributes = std::collections::HashMap::new(); attributes.insert("application", SECRET_ID); @@ -240,19 +240,19 @@ async fn secret_agent_stream_impl( let search_items = collection .search_items(attributes) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; let mut secrets = HashMap::new(); for item in &search_items { let name = item .get_attributes() .await - .map_err(|e| Arc::new(e))? + .map_err(Arc::new)? .get("name") .cloned() .unwrap_or_else(|| "unknown".to_string()); - let secret = item.get_secret().await.map_err(|e| Arc::new(e))?; - let secret: String = String::from_utf8(secret)?.into(); + let secret = item.get_secret().await.map_err(Arc::new)?; + let secret: String = String::from_utf8(secret)?; secrets.insert(name, SecureString::from(secret)); } let _ = resp_tx.send(secrets); @@ -382,7 +382,7 @@ impl SettingsSecretAgent { let conn = ConnectionSettingsProxy::builder( &zbus::Connection::system() .await - .or_else(|_| Err(fdo::Error::Failed("failed to get uuid".to_string())))?, + .map_err(|_| fdo::Error::Failed("failed to get uuid".to_string()))?, ) .path(connection_path)? .build() @@ -437,13 +437,9 @@ impl SettingsSecretAgent { hints: Vec, flags: u32, ) -> HashMap> { - match self - .get_secrets_inner(connection, connection_path, setting_name, hints, flags) + self.get_secrets_inner(connection, connection_path, setting_name, hints, flags) .await - { - Ok(result) => result, - Err(_) => HashMap::new(), - } + .unwrap_or_default() } /// SaveSecrets method @@ -472,9 +468,9 @@ impl SettingsSecretAgent { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; let conn_uuid = connection .get("connection") @@ -484,10 +480,8 @@ impl SettingsSecretAgent { .to_string(); let conn = - ConnectionSettingsProxy::builder(&zbus::Connection::system().await.or_else(|_| { - Err(Error::Zbus( - fdo::Error::Failed("failed to get uuid".to_string()).into(), - )) + ConnectionSettingsProxy::builder(&zbus::Connection::system().await.map_err(|_| { + Error::Zbus(fdo::Error::Failed("failed to get uuid".to_string()).into()) })?) .path(connection_path)? .build() @@ -498,7 +492,7 @@ impl SettingsSecretAgent { .get("connection") .and_then(|m| m.get("type")) .and_then(|v| v.downcast_ref::().ok()) - .map_or(false, |t| t == "vpn"); + .is_some_and(|t| t == "vpn"); let is_always_ask = is_connection_always_ask(&settings); let mut setting_attributes = std::collections::HashMap::new(); @@ -509,7 +503,7 @@ impl SettingsSecretAgent { let search_items = collection .search_items(setting_attributes.clone()) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; let mut result = HashMap::new(); let mut setting = HashMap::new(); @@ -518,16 +512,16 @@ impl SettingsSecretAgent { let name = item .get_attributes() .await - .map_err(|e| Arc::new(e))? + .map_err(Arc::new)? .get("name") .cloned() .unwrap_or_else(|| "unknown".to_string()); - let secret = item.get_secret().await.map_err(|e| Arc::new(e))?; - let secret: String = String::from_utf8(secret)?.into(); + let secret = item.get_secret().await.map_err(Arc::new)?; + let secret: String = String::from_utf8(secret)?; setting.insert(name, zbus::zvariant::OwnedValue::from(Str::from(secret))); } result.insert(setting_name, setting); - return Ok(result); + Ok(result) } else { let hints = parse_hints(hints); let mut requested = HashSet::new(); @@ -563,49 +557,47 @@ impl SettingsSecretAgent { && e.is_disconnected() { continue; - } else { - if let Ok(secret) = resp_rx.await { - let mut named_attribute = setting_attributes.clone(); - named_attribute.insert("name", key); - let _item = collection - .create_item( - "NetworkManager Secret", - named_attribute, - secret.unsecure().as_bytes(), - true, - "text/plain", - ) - .await - .map_err(|e| Arc::new(e))?; + } else if let Ok(secret) = resp_rx.await { + let mut named_attribute = setting_attributes.clone(); + named_attribute.insert("name", key); + let _item = collection + .create_item( + "NetworkManager Secret", + named_attribute, + secret.unsecure().as_bytes(), + true, + "text/plain", + ) + .await + .map_err(Arc::new)?; - setting.insert( - key.clone(), - zbus::zvariant::OwnedValue::from(Str::from(secret.unsecure())), - ); - } + setting.insert( + key.clone(), + zbus::zvariant::OwnedValue::from(Str::from(secret.unsecure())), + ); } } else if !is_always_ask { let mut pos = None; let mut pos_with_message = None; for item in &search_items { - let attributes = item.get_attributes().await.map_err(|e| Arc::new(e))?; - if let Some(value) = attributes.get("name") { - if value == key { - if let Some(saved_message) = attributes.get("message") { - if message.as_ref().is_some_and(|msg| msg == saved_message) { - pos_with_message = Some(item); - } - break; - } else { - pos = Some(item); + let attributes = item.get_attributes().await.map_err(Arc::new)?; + if let Some(value) = attributes.get("name") + && value == key + { + if let Some(saved_message) = attributes.get("message") { + if message.as_ref().is_some_and(|msg| msg == saved_message) { + pos_with_message = Some(item); } + break; + } else { + pos = Some(item); } } } if let Some(item) = pos_with_message.or(pos) { - let secret = item.get_secret().await.map_err(|e| Arc::new(e))?; - let secret: String = String::from_utf8(secret)?.into(); + let secret = item.get_secret().await.map_err(Arc::new)?; + let secret: String = String::from_utf8(secret)?; if is_vpn { // ask anyway, but offer the previous one as a hint let (resp_tx, resp_rx) = oneshot::channel(); @@ -628,28 +620,24 @@ impl SettingsSecretAgent { && e.is_disconnected() { continue; - } else { - if let Ok(secret) = resp_rx.await { - let mut named_attribute = setting_attributes.clone(); - named_attribute.insert("name", key); - let _item = collection - .create_item( - "NetworkManager Secret", - named_attribute, - secret.unsecure().as_bytes(), - true, - "text/plain", - ) - .await - .map_err(|e| Arc::new(e))?; + } else if let Ok(secret) = resp_rx.await { + let mut named_attribute = setting_attributes.clone(); + named_attribute.insert("name", key); + let _item = collection + .create_item( + "NetworkManager Secret", + named_attribute, + secret.unsecure().as_bytes(), + true, + "text/plain", + ) + .await + .map_err(Arc::new)?; - setting.insert( - key.clone(), - zbus::zvariant::OwnedValue::from(Str::from( - secret.unsecure(), - )), - ); - } + setting.insert( + key.clone(), + zbus::zvariant::OwnedValue::from(Str::from(secret.unsecure())), + ); } } else { setting.insert( @@ -664,7 +652,7 @@ impl SettingsSecretAgent { } } result.insert(setting_name, setting); - return Ok(result); + Ok(result) } } @@ -675,8 +663,8 @@ impl SettingsSecretAgent { ) -> Result<(), Error> { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; let conn_uuid = connection .get("connection") @@ -692,10 +680,10 @@ impl SettingsSecretAgent { let search_items = collection .search_items(attributes) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; for item in &search_items { - item.delete().await.map_err(|e| Arc::new(e))?; + item.delete().await.map_err(Arc::new)?; } Ok(()) } @@ -706,8 +694,8 @@ impl SettingsSecretAgent { ) -> Result<(), Error> { let ss = secret_service::SecretService::connect(secret_service::EncryptionType::Dh) .await - .map_err(|e| Arc::new(e))?; - let collection = ss.get_default_collection().await.map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; + let collection = ss.get_default_collection().await.map_err(Arc::new)?; let conn_uuid = connection .get("connection") .and_then(|m| m.get("uuid")) @@ -741,7 +729,7 @@ impl SettingsSecretAgent { "text/plain", ) .await - .map_err(|e| Arc::new(e))?; + .map_err(Arc::new)?; Ok(()) } else { Err(Error::NoPasswordForIdentifier("unknown".to_string())) diff --git a/subscriptions/sound/src/lib.rs b/subscriptions/sound/src/lib.rs index b99e766..589065a 100644 --- a/subscriptions/sound/src/lib.rs +++ b/subscriptions/sound/src/lib.rs @@ -251,7 +251,7 @@ impl Model { None } else { - self.node_names.get(node_id).map(|name| name.clone()) + self.node_names.get(node_id).cloned() }; tokio::task::spawn(async move { @@ -327,10 +327,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).cloned() }; tokio::task::spawn(async move { @@ -527,10 +525,10 @@ impl Model { } pipewire::Event::AddProfile(id, index, profile) => { - if let Some(p) = self.active_profiles.get_mut(id) { - if p.index == profile.index { - *p = profile.clone(); - } + if let Some(p) = self.active_profiles.get_mut(id) + && p.index == profile.index + { + *p = profile.clone(); } let profiles = self.device_profiles.entry(id).or_default(); @@ -716,12 +714,12 @@ impl Model { if let Some(pos) = self.sink_node_ids.iter().position(|&node_id| node_id == id) { self.sink_node_ids.remove(pos); self.sinks.remove(pos); - if let Some(node_id) = self.active_sink_node { - if id == node_id { - self.active_sink = None; - self.active_sink_node = None; - self.active_sink_node_name.clear(); - } + if let Some(node_id) = self.active_sink_node + && id == node_id + { + self.active_sink = None; + self.active_sink_node = None; + self.active_sink_node_name.clear(); } } else if let Some(pos) = self .source_node_ids @@ -730,12 +728,12 @@ impl Model { { self.source_node_ids.remove(pos); self.sources.remove(pos); - if let Some(node_id) = self.active_source_node { - if id == node_id { - self.active_source = None; - self.active_source_node = None; - self.active_source_node_name.clear(); - } + if let Some(node_id) = self.active_source_node + && id == node_id + { + self.active_source = None; + self.active_source_node = None; + self.active_source_node_name.clear(); } }