chore: apply recommendations from clippy

This commit is contained in:
Cheong Lau 2025-10-04 10:51:18 +10:00 committed by GitHub
parent cec55dafd7
commit 8e0f1c4a09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 720 additions and 824 deletions

View file

@ -116,7 +116,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
destroy_popup(p),
cosmic::task::future(
set_tick(Duration::from_secs(10))
.map(|_| cosmic::Action::App(Message::Ignore)),
.map(|()| cosmic::Action::App(Message::Ignore)),
),
]);
} else {
@ -133,7 +133,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
None,
);
let tx = self.bluer_sender.as_ref().cloned();
let tx = self.bluer_sender.clone();
return Task::batch(vec![
iced::Task::perform(
async {
@ -141,11 +141,11 @@ impl cosmic::Application for CosmicBluetoothApplet {
let _ = tx.send(BluerRequest::StateUpdate).await;
}
},
|_| cosmic::action::app(Message::Ignore),
|()| cosmic::action::app(Message::Ignore),
),
get_popup(popup_settings),
cosmic::task::future(set_tick(Duration::from_secs(3)))
.map(|_: ()| cosmic::Action::App(Message::Ignore)),
.map(|()| cosmic::Action::App(Message::Ignore)),
]);
}
}
@ -160,7 +160,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
err_msg,
} => {
if let Some(err_msg) = err_msg {
eprintln!("bluetooth request error: {}", err_msg);
eprintln!("bluetooth request error: {err_msg}");
}
if self.bluer_state.bluetooth_enabled != state.bluetooth_enabled {
self.timeline
@ -178,7 +178,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
BluerRequest::StateUpdate
if self.popup.is_some() && self.bluer_sender.is_some() =>
{
let tx = self.bluer_sender.as_ref().cloned().unwrap();
let tx = self.bluer_sender.clone().unwrap();
tokio::spawn(async move {
// sleep for a bit before requesting state update again
tokio::time::sleep(Duration::from_millis(3000)).await;
@ -186,7 +186,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
});
}
_ => {}
};
}
}
BluerEvent::Init { sender, state } => {
self.bluer_sender.replace(sender);
@ -270,7 +270,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
}
_ => {} // TODO
}
if let Some(tx) = self.bluer_sender.as_mut().cloned() {
if let Some(tx) = self.bluer_sender.clone() {
tokio::spawn(async move {
let _ = tx.send(r).await;
});
@ -295,7 +295,8 @@ impl cosmic::Application for CosmicBluetoothApplet {
self.popup = None;
}
return cosmic::task::future(
set_tick(Duration::from_secs(10)).map(|_| cosmic::Action::App(Message::Ignore)),
set_tick(Duration::from_secs(10))
.map(|()| cosmic::Action::App(Message::Ignore)),
);
}
Message::OpenSettings => {
@ -305,7 +306,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
app_id: Self::APP_ID.to_string(),
exec,
});
};
}
}
Message::Token(u) => match u {
TokenUpdate::Init(tx) => {
@ -347,7 +348,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
Task::none()
}
fn view(&self) -> Element<Message> {
fn view(&self) -> Element<'_, Message> {
self.core
.applet
.icon_button(&self.icon_name)
@ -355,7 +356,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
.into()
}
fn view_window(&self, _id: window::Id) -> Element<Message> {
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
let Spacing {
space_xxs, space_s, ..
} = theme::active().cosmic().spacing;
@ -363,10 +364,9 @@ impl cosmic::Application for CosmicBluetoothApplet {
let mut known_bluetooth = vec![];
// PERF: This should be pre-filtered in an update.
for dev in self.bluer_state.devices.iter().filter(|d| {
!self
.request_confirmation
self.request_confirmation
.as_ref()
.map_or(false, |(dev, _, _)| d.address == dev.address)
.is_none_or(|(dev, _, _)| d.address != dev.address)
}) {
let mut row = row![
icon::from_name(dev.icon).size(16).symbolic(true),
@ -380,13 +380,13 @@ impl cosmic::Application for CosmicBluetoothApplet {
if let Some(battery) = dev.battery_percent {
let icon = match battery {
b if b >= 20 && b < 40 => "battery-low",
b if (20..40).contains(&b) => "battery-low",
b if b < 20 => "battery-caution",
_ => "battery",
};
let status = row!(
icon::from_name(icon).symbolic(true).size(14),
text::body(format!("{}%", battery))
text::body(format!("{battery}%"))
)
.align_y(Alignment::Center)
.spacing(2)
@ -416,7 +416,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
);
}
BluerDeviceStatus::Disconnected | BluerDeviceStatus::Pairing => continue,
};
}
known_bluetooth.push(
menu_button(row)
@ -529,10 +529,10 @@ impl cosmic::Application for CosmicBluetoothApplet {
matches!(
d.status,
BluerDeviceStatus::Disconnected | BluerDeviceStatus::Pairing
) && !self
) && self
.request_confirmation
.as_ref()
.map_or(false, |(dev, _, _)| d.address == dev.address)
.is_none_or(|(dev, _, _)| d.address != dev.address)
&& (d.has_name() || d.is_known_device_type())
}) {
let row = row![

View file

@ -95,7 +95,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
}
retry_count = retry_count.saturating_add(1);
_ = tokio::time::sleep(Duration::from_millis(
() = tokio::time::sleep(Duration::from_millis(
2_u64.saturating_pow(retry_count).min(68719476734),
))
.await;
@ -156,7 +156,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
event_handler(event).await;
// Consume any additional available events.
let mut count = 0;
while let Some(event) = session_rx.try_recv().ok() {
while let Ok(event) = session_rx.try_recv() {
event_handler(event).await;
count += 1;
if count == 100 {
@ -165,7 +165,7 @@ pub fn bluetooth_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
}
} else {
break;
};
}
session_state.rx = Some(session_rx);
interval.tick().await;
@ -271,10 +271,9 @@ impl BluerDevice {
#[inline(never)]
pub async fn from_device(device: &bluer::Device) -> Self {
let (mut name, is_paired, is_trusted, is_connected, battery_percent, icon) = futures::join!(
device.name().map(|res| res
.ok()
.flatten()
.unwrap_or_else(|| device.address().to_string())),
device
.name()
.map(|res| res.ok().flatten().unwrap_or(device.address().to_string())),
device.is_paired().map(Result::unwrap_or_default),
device.is_trusted().map(Result::unwrap_or_default),
device.is_connected().map(Result::unwrap_or_default),
@ -286,7 +285,7 @@ impl BluerDevice {
if name.is_empty() {
name = device.address().to_string();
};
}
let status = if is_connected {
BluerDeviceStatus::Connected
@ -385,9 +384,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_1.clone();
let tx_clone = tx_clone_1.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let _ = tx_clone
.send(BluerSessionEvent::AgentEvent(
@ -397,16 +395,15 @@ impl BluerSessionState {
))
.await;
let pin_code = fastrand::u32(0..999999);
Ok(format!("{:06}", pin_code))
Ok(format!("{pin_code:06}"))
})
})),
display_pin_code: Some(Box::new(move |req| {
let agent_clone = adapter_clone_2.clone();
let tx_clone = tx_clone_2.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let _ = tx_clone
.send(BluerSessionEvent::AgentEvent(
@ -424,9 +421,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_3.clone();
let tx_clone = tx_clone_3.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let _ = tx_clone
.send(BluerSessionEvent::AgentEvent(
@ -443,9 +439,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_4.clone();
let tx_clone = tx_clone_4.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let _ = tx_clone
.send(BluerSessionEvent::AgentEvent(
@ -462,9 +457,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_5.clone();
let tx_clone = tx_clone_5.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let (tx, mut rx) = channel(1);
let _ = tx_clone
@ -487,9 +481,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_6.clone();
let tx_clone = tx_clone_6.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let (tx, mut rx) = channel(1);
let _ = tx_clone
@ -511,9 +504,8 @@ impl BluerSessionState {
let agent_clone = adapter_clone_7.clone();
let tx_clone = tx_clone_7.clone();
Box::pin(async move {
let device = match agent_clone.device(req.device) {
Ok(d) => d,
Err(_) => return Err(bluer::agent::ReqError::Rejected),
let Ok(device) = agent_clone.device(req.device) else {
return Err(bluer::agent::ReqError::Rejected);
};
let (tx, mut rx) = channel(1);
// TODO better describe the service to the user
@ -614,16 +606,14 @@ impl BluerSessionState {
let mut new_devices = Vec::new();
let mut interval = tokio::time::interval(Duration::from_secs(10));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
let mut change_stream =
match adapter_clone.discover_devices_with_changes().await {
Ok(stream) => stream,
Err(_) => {
tick(&mut interval).await;
return;
}
};
let Ok(mut change_stream) =
adapter_clone.discover_devices_with_changes().await
else {
tick(&mut interval).await;
return;
};
while let Some(_) = change_stream.next().await {
while change_stream.next().await.is_some() {
new_devices = build_device_list(new_devices, &adapter_clone).await;
for d in new_devices
.iter()
@ -679,7 +669,7 @@ impl BluerSessionState {
match &req_clone {
BluerRequest::SetBluetoothEnabled(enabled) => {
if let Err(e) = adapter_clone.set_powered(*enabled).await {
tracing::error!("Failed to power off bluetooth adapter. {e:?}")
tracing::error!("Failed to power off bluetooth adapter. {e:?}");
}
// rfkill will be persisted after reboot
@ -695,8 +685,8 @@ impl BluerSessionState {
.ok()
.and_then(|o| {
let lines = String::from_utf8(o.stdout).ok()?;
lines.split("\n").into_iter().find_map(|row| {
let (id, cname) = row.trim().split_once(" ")?;
lines.split('\n').into_iter().find_map(|row| {
let (id, cname) = row.trim().split_once(' ')?;
(name == cname).then_some(id.to_string())
})
})
@ -768,7 +758,7 @@ impl BluerSessionState {
}
}
BluerRequest::StateUpdate => {}
};
}
let _ = tx_clone
.send(BluerSessionEvent::RequestResponse {
@ -820,7 +810,7 @@ async fn build_device_list(mut devices: Vec<BluerDevice>, adapter: &Adapter) ->
.collect::<FuturesUnordered<_>>();
while let Some(device) = device_stream.next().await {
devices.push(device)
devices.push(device);
}
devices.sort();

View file

@ -44,6 +44,6 @@ pub fn localize() {
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
if let Err(error) = localizer.select(&requested_languages) {
eprintln!("Error while loading language for App List {}", error);
eprintln!("Error while loading language for App List {error}");
}
}