chore: clippy

This commit is contained in:
Vukašin Vojinović 2026-02-19 18:33:47 +01:00 committed by Michael Murphy
parent 6e022755f1
commit 787c5ed49f
14 changed files with 218 additions and 243 deletions

View file

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

View file

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

View file

@ -18,8 +18,8 @@ impl HwAddress {
.ok()
.map(|address| HwAddress { address })
}
pub fn from_string(arg: &String) -> Option<Self> {
HwAddress::from_str(arg.as_str())
pub fn from_string(arg: &str) -> Option<Self> {
HwAddress::from_str(arg)
}
}

View file

@ -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::<zbus::zvariant::Str>().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::<zbus::zvariant::Str>().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::<zbus::zvariant::Str>().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()

View file

@ -16,7 +16,7 @@ use zbus::{
pub type SecretSender = Arc<tokio::sync::Mutex<Option<tokio::sync::oneshot::Sender<SecureString>>>>;
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<String>,
flags: u32,
) -> HashMap<String, HashMap<String, zbus::zvariant::OwnedValue>> {
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::<String>().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()))

View file

@ -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();
}
}