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),
PageMessage(crate::pages::Message),
#[cfg(feature = "wayland")]
PanelConfig(CosmicPanelConfig),
PanelConfig(Box<CosmicPanelConfig>),
#[cfg(any(feature = "page-window-management", feature = "page-accessibility"))]
CompConfig(CosmicCompConfig),
CompConfig(Box<CosmicCompConfig>),
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))
}),
];

View file

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

View file

@ -112,7 +112,7 @@ impl page::Page<crate::pages::Message> 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();

View file

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

View file

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

View file

@ -433,7 +433,7 @@ pub enum Message {
OpacityApply,
OutputAdded(String, WlOutput),
OutputRemoved(WlOutput),
PanelConfig(CosmicPanelConfig),
PanelConfig(Box<CosmicPanelConfig>),
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 => {}

View file

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

View file

@ -262,7 +262,7 @@ impl page::Page<crate::pages::Message> 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();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -26,16 +26,13 @@ pub fn watch() -> impl Stream<Item = Message> + 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