chore: clippy

This commit is contained in:
Ashley Wulber 2025-12-31 11:45:31 -05:00 • committed by Michael Murphy
parent 1eae90fd0d
commit 1eb345085d
14 changed files with 113 additions and 124 deletions

View file

@ -164,9 +164,9 @@ pub enum Message {
Page(page::Entity), Page(page::Entity),
PageMessage(crate::pages::Message), PageMessage(crate::pages::Message),
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
PanelConfig(CosmicPanelConfig), PanelConfig(Box<CosmicPanelConfig>),
#[cfg(any(feature = "page-window-management", feature = "page-accessibility"))] #[cfg(any(feature = "page-window-management", feature = "page-accessibility"))]
CompConfig(CosmicCompConfig), CompConfig(Box<CosmicCompConfig>),
SearchActivate, SearchActivate,
SearchChanged(String), SearchChanged(String),
SearchClear, SearchClear,
@ -333,7 +333,7 @@ impl cosmic::Application for SettingsApp {
tracing::error!(?why, "panel config load error"); 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. // TODO: This should only be active when the dock page is active.
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
@ -344,7 +344,7 @@ impl cosmic::Application for SettingsApp {
tracing::error!(?why, "dock config load error"); tracing::error!(?why, "dock config load error");
} }
Message::PanelConfig(update.config) Message::PanelConfig(Box::new(update.config))
}), }),
page.subscription(self.core()).map(Message::PageMessage), page.subscription(self.core()).map(Message::PageMessage),
#[cfg(any(feature = "page-window-management", feature = "page-accessibility"))] #[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"); tracing::error!(?why, "comp config load error");
} }
Message::CompConfig(update.config) Message::CompConfig(Box::new(update.config))
}), }),
]; ];

View file

@ -38,7 +38,7 @@ pub struct Page {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
Event(wayland::AccessibilityEvent), Event(wayland::AccessibilityEvent),
CompConfigUpdate(cosmic_comp_config::CosmicCompConfig), CompConfigUpdate(Box<cosmic_comp_config::CosmicCompConfig>),
ProtocolUnavailable, ProtocolUnavailable,
SetMagnifier(bool), SetMagnifier(bool),
SetMouseShortcuts(bool), SetMouseShortcuts(bool),

View file

@ -112,7 +112,7 @@ impl page::Page<crate::pages::Message> for Page {
tasks.push(cosmic::task::future(on_enter())); tasks.push(cosmic::task::future(on_enter()));
let refresh_pending = self.refresh_pending.clone(); 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 (canceller, cancelled) = oneshot::channel::<()>();
let runtime = tokio::runtime::Handle::current(); let runtime = tokio::runtime::Handle::current();

View file

@ -597,8 +597,8 @@ impl Page {
(panel_config.name == "Dock").then_some(panel_config) (panel_config.name == "Dock").then_some(panel_config)
}); });
if let Some(dock_config_helper) = dock_config_helper.as_ref() { if let Some(dock_config_helper) = dock_config_helper.as_ref()
if let Some(dock_config) = dock_config.as_mut() { && let Some(dock_config) = dock_config.as_mut() {
let padding = match roundness { let padding = match roundness {
Roundness::Round => 4, Roundness::Round => 4,
Roundness::SlightlyRound => 4, Roundness::SlightlyRound => 4,
@ -609,7 +609,6 @@ impl Page {
tracing::error!(?why, "Error updating dock padding"); tracing::error!(?why, "Error updating dock padding");
} }
} }
}
} }
// TODO: cache panel and dock configs so that they needn't be re-read // TODO: cache panel and dock configs so that they needn't be re-read

View file

@ -170,7 +170,7 @@ pub enum Message {
ReorderCenter(Vec<Applet<'static>>), ReorderCenter(Vec<Applet<'static>>),
ReorderEnd(Vec<Applet<'static>>), ReorderEnd(Vec<Applet<'static>>),
Applets(Vec<Applet<'static>>), Applets(Vec<Applet<'static>>),
PanelConfig(CosmicPanelConfig), PanelConfig(Box<CosmicPanelConfig>),
StartDnd(Applet<'static>), StartDnd(Applet<'static>),
// DnDTask(Arc<Box<dyn Send + Sync + Fn() -> ActionInner>>), // DnDTask(Arc<Box<dyn Send + Sync + Fn() -> ActionInner>>),
Search(String), Search(String),
@ -297,7 +297,7 @@ impl Page {
pub fn update(&mut self, message: Message) -> Task<app::Message> { pub fn update(&mut self, message: Message) -> Task<app::Message> {
match message { match message {
Message::PanelConfig(c) => { Message::PanelConfig(c) => {
self.current_config = Some(c); self.current_config = Some(*c);
} }
Message::ReorderStart(start_list) => { Message::ReorderStart(start_list) => {

View file

@ -433,7 +433,7 @@ pub enum Message {
OpacityApply, OpacityApply,
OutputAdded(String, WlOutput), OutputAdded(String, WlOutput),
OutputRemoved(WlOutput), OutputRemoved(WlOutput),
PanelConfig(CosmicPanelConfig), PanelConfig(Box<CosmicPanelConfig>),
ResetPanel, ResetPanel,
FullReset, FullReset,
Surface(surface::Action), Surface(surface::Action),
@ -668,7 +668,7 @@ impl PageInner {
} }
} }
Message::PanelConfig(c) => { Message::PanelConfig(c) => {
self.panel_config = Some(c); self.panel_config = Some(*c);
return Task::none(); return Task::none();
} }
Message::ResetPanel | Message::FullReset => {} Message::ResetPanel | Message::FullReset => {}

View file

@ -20,7 +20,7 @@ use tracing::error;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Message { pub enum Message {
SuperKey(usize), SuperKey(usize),
CompConfigUpdate(CosmicCompConfig), CompConfigUpdate(Box<CosmicCompConfig>),
SetFocusFollowsCursor(bool), SetFocusFollowsCursor(bool),
SaveFocusFollowsCursorDelay(bool), SaveFocusFollowsCursorDelay(bool),
SetFocusFollowsCursorDelay(String), SetFocusFollowsCursorDelay(String),

View file

@ -262,7 +262,7 @@ impl page::Page<crate::pages::Message> for Page {
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
{ {
let refreshing_page = self.refreshing_page.clone(); 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 (canceller, cancelled) = oneshot::channel::<()>();
let runtime = tokio::runtime::Handle::current(); let runtime = tokio::runtime::Handle::current();
@ -555,15 +555,14 @@ impl Page {
return self.toggle_display(true); return self.toggle_display(true);
} }
if let Some(v) = self.mirror_map.get(k) { if let Some(v) = self.mirror_map.get(k)
if v.equivalent(&self.active_display) { && v.equivalent(&self.active_display) {
if let Some(output) = self.list.outputs.get(k) { if let Some(output) = self.list.outputs.get(k) {
return self.exec_randr(output, Randr::Toggle(true)); return self.exec_randr(output, Randr::Toggle(true));
} else { } else {
return Task::none(); return Task::none();
} }
} }
}
} }
return Task::none(); return Task::none();

View file

@ -653,7 +653,7 @@ impl Page {
), ),
( (
"password".to_string(), "password".to_string(),
password.clone().into(), password.clone(),
), ),
]), ]),
applied_tx, applied_tx,
@ -733,7 +733,7 @@ impl Page {
secrets: HashMap::from_iter([ secrets: HashMap::from_iter([
// username and password // username and password
("username".to_string(), username.clone().into()), ("username".to_string(), username.clone().into()),
("password".to_string(), password.clone().into()), ("password".to_string(), password.clone()),
]), ]),
applied_tx, applied_tx,
}) })
@ -793,7 +793,7 @@ impl Page {
id: name.clone(), id: name.clone(),
uuid: Arc::from(""), uuid: Arc::from(""),
username: None, username: None,
description: description, description,
password: previous, password: previous,
password_hidden: true, password_hidden: true,
tx, tx,

View file

@ -378,7 +378,7 @@ impl Page {
self.connecting.remove(ssid.as_ref()); self.connecting.remove(ssid.as_ref());
} else { } else {
self.dialog = Some(WiFiDialog::Password { self.dialog = Some(WiFiDialog::Password {
ssid: ssid.into(), ssid,
identity: matches!(network_type, NetworkType::EAP) identity: matches!(network_type, NetworkType::EAP)
.then(String::new), .then(String::new),
hw_address, hw_address,

View file

@ -447,6 +447,7 @@ impl Page {
} }
} }
#[allow(clippy::too_many_arguments)]
fn device_view<'a>( fn device_view<'a>(
&'a self, &'a self,
spacing: cosmic::cosmic_theme::Spacing, spacing: cosmic::cosmic_theme::Spacing,

View file

@ -216,21 +216,19 @@ impl Page {
Message::ToggleOverAmplificationSink(enabled) => { Message::ToggleOverAmplificationSink(enabled) => {
self.amplification_sink = enabled; self.amplification_sink = enabled;
if let Some(config) = &self.sound_config { if let Some(config) = &self.sound_config
if let Err(why) = config.set(AMPLIFICATION_SINK, enabled) { && let Err(why) = config.set(AMPLIFICATION_SINK, enabled) {
tracing::error!(?why, "Failed to save over amplification setting"); tracing::error!(?why, "Failed to save over amplification setting");
} }
}
} }
Message::ToggleOverAmplificationSource(enabled) => { Message::ToggleOverAmplificationSource(enabled) => {
self.amplification_source = enabled; self.amplification_source = enabled;
if let Some(config) = &self.sound_config { if let Some(config) = &self.sound_config
if let Err(why) = config.set(AMPLIFICATION_SOURCE, enabled) { && let Err(why) = config.set(AMPLIFICATION_SOURCE, enabled) {
tracing::error!(?why, "Failed to save over amplification setting"); tracing::error!(?why, "Failed to save over amplification setting");
} }
}
} }
Message::SetProfile(object_id, index) => { Message::SetProfile(object_id, index) => {

View file

@ -22,13 +22,14 @@ pub struct Info {
impl Info { impl Info {
pub fn load() -> Info { pub fn load() -> Info {
let mut info = Info::default(); let mut info = Info {
os_architecture: architecture(),
info.os_architecture = architecture(); kernel_version: kernel_version(),
info.kernel_version = kernel_version(); hardware_model: hardware_model(),
info.hardware_model = hardware_model(); operating_system: operating_system(),
info.operating_system = operating_system(); processor: processor_name(),
info.processor = processor_name(); ..Default::default()
};
let mut sys = sysinfo::System::new(); let mut sys = sysinfo::System::new();
let disks = sysinfo::Disks::new_with_refreshed_list(); 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 DMI_DIR: &str = "/sys/devices/virtual/dmi/id/";
const VERSION_IGNORING_PRODUCTS: &[&str] = &["Dev One"]; 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()) .map(|s| s.trim().to_string())
.unwrap_or_default(); .unwrap_or_default();
@ -206,25 +207,25 @@ fn hardware_model() -> String {
let mut model = sys_vendor.clone(); let mut model = sys_vendor.clone();
if let Some(mut name) = 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
// Ensure that the name does not contain the vendor name = name
name = name .strip_prefix(&sys_vendor)
.strip_prefix(&sys_vendor) .map(|s| s.trim().to_string())
.map(|s| s.trim().to_string()) .unwrap_or(name);
.unwrap_or(name);
model.push(' '); model.push(' ');
model.push_str(&name); model.push_str(&name);
if let Some(version) = if let Some(version) =
read_to_string(&format!("{DMI_DIR}board_version")).map(|s| s.trim().to_string()) read_to_string(format!("{DMI_DIR}board_version")).map(|s| s.trim().to_string())
{ && !version.is_empty()
if !version.is_empty() && !VERSION_IGNORING_PRODUCTS.contains(&name.as_str()) { && !VERSION_IGNORING_PRODUCTS.contains(&name.as_str())
model.push_str(&format!(" ({version})")); {
} 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)" // 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) // 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_start) = line.rfind('[')
if let Some(ids_end) = line.rfind(']') { && let Some(ids_end) = line.rfind(']')
let ids = &line[ids_start + 1..ids_end]; {
let ids = &line[ids_start + 1..ids_end];
if let Some(colon_pos) = ids.find(':') { if let Some(colon_pos) = ids.find(':') {
let vendor_id_str = &ids[..colon_pos]; let vendor_id_str = &ids[..colon_pos];
let device_id_str = &ids[colon_pos + 1..]; let device_id_str = &ids[colon_pos + 1..];
if let (Ok(vendor_id), Ok(device_id)) = ( if let (Ok(vendor_id), Ok(device_id)) = (
u32::from_str_radix(vendor_id_str, 16), u32::from_str_radix(vendor_id_str, 16),
u32::from_str_radix(device_id_str, 16), u32::from_str_radix(device_id_str, 16),
) { ) && let Some(name_start) = line.find(": ")
if let Some(name_start) = line.find(": ") { {
let full_name = line[name_start + 2..ids_start].trim(); let full_name = line[name_start + 2..ids_start].trim();
// Look for marketing name in brackets like "GP108M [GeForce MX150]" // Look for marketing name in brackets like "GP108M [GeForce MX150]"
// We prefer the marketing name over the chip code // We prefer the marketing name over the chip code
let gpu_name = if let Some(bracket_start) = full_name.find('[') { let gpu_name = if let Some(bracket_start) = full_name.find('[') {
if let Some(bracket_end) = full_name.find(']') { if let Some(bracket_end) = full_name.find(']') {
let vendor_part = full_name[..bracket_start].trim(); let vendor_part = full_name[..bracket_start].trim();
let marketing_name = let marketing_name = full_name[bracket_start + 1..bracket_end].trim();
full_name[bracket_start + 1..bracket_end].trim();
let vendor = vendor_part let vendor =
.split_whitespace() vendor_part.split_whitespace().next().unwrap_or(vendor_part);
.next()
.unwrap_or(vendor_part);
format!("{} {}", vendor, marketing_name) format!("{} {}", vendor, marketing_name)
} else { } else {
full_name.to_string() full_name.to_string()
}
} else {
full_name.to_string()
};
if !gpu_name.is_empty() {
gpus.push((vendor_id, device_id, gpu_name));
}
} }
} 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<u32, String> {
// Or with marketing name: "00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P GT2 [Iris Xe Graphics] [8086:46a6] (rev 0c)" // 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 // 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_start) = line.rfind('[')
if let Some(ids_end) = line.rfind(']') { && let Some(ids_end) = line.rfind(']')
let ids = &line[ids_start + 1..ids_end]; {
let ids = &line[ids_start + 1..ids_end];
// Parse vendor:device format like "8086:5a85" // Parse vendor:device format like "8086:5a85"
if let Some(colon_pos) = ids.find(':') { if let Some(colon_pos) = ids.find(':') {
let device_id_str = &ids[colon_pos + 1..]; let device_id_str = &ids[colon_pos + 1..];
if let Ok(device_id) = u32::from_str_radix(device_id_str, 16) { if let Ok(device_id) = u32::from_str_radix(device_id_str, 16) {
// Extract the GPU name between ": " and the last "[" // Extract the GPU name between ": " and the last "["
if let Some(name_start) = line.find(": ") { if let Some(name_start) = line.find(": ") {
let full_name = line[name_start + 2..ids_start].trim(); let full_name = line[name_start + 2..ids_start].trim();
let gpu_name = full_name let gpu_name = full_name
.replace(" Corporation", "") .replace(" Corporation", "")
.replace(" [Intel Graphics]", ""); .replace(" [Intel Graphics]", "");
if !gpu_name.is_empty() { if !gpu_name.is_empty() {
gpu_map.insert(device_id, gpu_name); gpu_map.insert(device_id, gpu_name);
}
} }
} }
} }

View file

@ -26,16 +26,13 @@ pub fn watch() -> impl Stream<Item = Message> + MaybeSend + 'static {
let receiver = sender.clone(); let receiver = sender.clone();
_ = emitter _ = emitter
.send( .send(Message::SubHandle(Arc::new(SubscriptionHandle {
Message::SubHandle(Arc::new(SubscriptionHandle { cancel_tx,
cancel_tx, pipewire: pipewire::run(move |event| {
pipewire: pipewire::run(move |event| { sender.0.lock().unwrap().push(event);
sender.0.lock().unwrap().push(event); sender.1.notify_one();
sender.1.notify_one(); }),
}), })))
}))
.into(),
)
.await; .await;
let forwarder = Box::pin(async { let forwarder = Box::pin(async {
@ -215,7 +212,7 @@ impl Model {
self.sink_volume_debounce = true; self.sink_volume_debounce = true;
return cosmic::Task::future(async move { return cosmic::Task::future(async move {
tokio::time::sleep(Duration::from_millis(128)).await; tokio::time::sleep(Duration::from_millis(128)).await;
Message::SinkVolumeApply(id).into() Message::SinkVolumeApply(id)
}); });
} }
@ -253,10 +250,8 @@ impl Model {
} }
None None
} else if let Some(name) = self.node_names.get(node_id) {
Some(name.clone())
} else { } else {
None self.node_names.get(node_id).map(|name| name.clone())
}; };
tokio::task::spawn(async move { tokio::task::spawn(async move {
@ -294,7 +289,7 @@ impl Model {
self.sink_volume_debounce = true; self.sink_volume_debounce = true;
return cosmic::Task::future(async move { return cosmic::Task::future(async move {
tokio::time::sleep(Duration::from_millis(128)).await; 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; self.source_volume_debounce = true;
return cosmic::Task::future(async move { return cosmic::Task::future(async move {
tokio::time::sleep(Duration::from_millis(128)).await; 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), fn(&mut Self, NodeId),
) = match route.direction { ) = match route.direction {
pipewire::Direction::Output => ( pipewire::Direction::Output => (
self.active_sink_device.clone(), self.active_sink_device,
&self.sink_node_ids, &self.sink_node_ids,
Self::set_default_sink_id, Self::set_default_sink_id,
), ),
pipewire::Direction::Input => ( pipewire::Direction::Input => (
self.active_source_device.clone(), self.active_source_device,
&self.source_node_ids, &self.source_node_ids,
Self::set_default_source_id, Self::set_default_source_id,
), ),
@ -685,7 +680,7 @@ impl Model {
if routes.len() < index as usize + 1 { if routes.len() < index as usize + 1 {
let additional = (index as usize + 1) - routes.capacity(); let additional = (index as usize + 1) - routes.capacity();
routes.reserve_exact(additional); 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; routes[index as usize] = route;
} }
@ -815,7 +810,7 @@ impl Model {
let (active_profile, indexes, descriptions) = self let (active_profile, indexes, descriptions) = self
.active_profiles .active_profiles
.get(device_id) .get(device_id)
.and_then(|profile| { .map(|profile| {
let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles
.iter() .iter()
.filter(|p| { .filter(|p| {
@ -835,7 +830,7 @@ impl Model {
.find(|(_, p)| p.index == profile.index) .find(|(_, p)| p.index == profile.index)
.map(|(pos, _)| pos); .map(|(pos, _)| pos);
Some((pos, indexes, descriptions)) (pos, indexes, descriptions)
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles let (indexes, descriptions): (Vec<_>, Vec<_>) = profiles