chore: apply recommendations from clippy
This commit is contained in:
parent
cec55dafd7
commit
8e0f1c4a09
56 changed files with 720 additions and 824 deletions
|
|
@ -261,7 +261,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
}
|
||||
return cosmic::iced::Task::perform(
|
||||
tokio::time::sleep(Duration::from_millis(200)),
|
||||
|_| cosmic::Action::App(Message::SetKbdBrightnessDebounced),
|
||||
|()| cosmic::Action::App(Message::SetKbdBrightnessDebounced),
|
||||
);
|
||||
}
|
||||
Message::SetScreenBrightnessDebounced => {
|
||||
|
|
@ -276,7 +276,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
}
|
||||
return cosmic::iced::Task::perform(
|
||||
tokio::time::sleep(Duration::from_millis(200)),
|
||||
|_| cosmic::Action::App(Message::SetScreenBrightnessDebounced),
|
||||
|()| cosmic::Action::App(Message::SetScreenBrightnessDebounced),
|
||||
);
|
||||
}
|
||||
Message::ReleaseKbdBrightness => {
|
||||
|
|
@ -410,7 +410,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
});
|
||||
} else {
|
||||
tracing::error!("Wayland tx is None");
|
||||
};
|
||||
}
|
||||
}
|
||||
Message::Token(u) => match u {
|
||||
TokenUpdate::Init(tx) => {
|
||||
|
|
@ -433,17 +433,13 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
self.update_trigger = Some(tx);
|
||||
}
|
||||
Message::GpuOn(path, name, app_list) => {
|
||||
let toggled = self
|
||||
.gpus
|
||||
.get(&path)
|
||||
.map(|data| data.toggled)
|
||||
.unwrap_or_default();
|
||||
let toggled = self.gpus.get(&path).is_some_and(|data| data.toggled);
|
||||
self.gpus.insert(
|
||||
path,
|
||||
GPUData {
|
||||
name,
|
||||
app_list,
|
||||
toggled,
|
||||
app_list,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -483,7 +479,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
fn view(&self) -> Element<'_, Message> {
|
||||
let btn = self
|
||||
.core
|
||||
.applet
|
||||
|
|
@ -491,7 +487,9 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
.on_press_down(Message::TogglePopup)
|
||||
.into();
|
||||
|
||||
let content = if !self.gpus.is_empty() {
|
||||
let content = if self.gpus.is_empty() {
|
||||
btn
|
||||
} else {
|
||||
let dot = container(vertical_space().height(Length::Fixed(0.0)))
|
||||
.padding(2.0)
|
||||
.class(cosmic::style::Container::Custom(Box::new(|theme| {
|
||||
|
|
@ -517,14 +515,12 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
.align_y(Alignment::Center)
|
||||
.into(),
|
||||
}
|
||||
} else {
|
||||
btn
|
||||
};
|
||||
|
||||
self.core.applet.autosize_window(content).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;
|
||||
|
|
@ -740,7 +736,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
|||
width: 0.0,
|
||||
color: Color::TRANSPARENT,
|
||||
},
|
||||
shadow: Default::default(),
|
||||
shadow: Shadow::default(),
|
||||
icon_color: Some(Color::TRANSPARENT),
|
||||
}
|
||||
},))),
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub async fn get_power_profile(daemon: Backend<'_>) -> Result<Power> {
|
|||
"Battery" => Ok(Power::Battery),
|
||||
"Balanced" => Ok(Power::Balanced),
|
||||
"Performance" => Ok(Power::Performance),
|
||||
_ => panic!("Unknown power profile: {}", power),
|
||||
_ => panic!("Unknown power profile: {power}"),
|
||||
}
|
||||
}
|
||||
Backend::PowerProfilesDaemon(ppd) => {
|
||||
|
|
@ -226,7 +226,7 @@ pub async fn get_charging_limit() -> anyhow::Result<bool> {
|
|||
Backend::PowerProfilesDaemon(_) => {
|
||||
tracing::info!("Power Profiles Daemon is not supported.");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
anyhow::bail!("Unsupported")
|
||||
|
|
@ -245,7 +245,7 @@ pub async fn set_charging_limit() -> Result<()> {
|
|||
"Setting charging limit via Power Profiles Daemon is not supported."
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ async fn is_desktop() -> bool {
|
|||
}
|
||||
|
||||
async fn powered_on(path: impl AsRef<Path>) -> bool {
|
||||
let Some(component) = path.as_ref().components().last() else {
|
||||
let Some(component) = path.as_ref().components().next_back() else {
|
||||
return true;
|
||||
};
|
||||
let name_str = component.as_os_str();
|
||||
|
|
@ -87,7 +87,7 @@ async fn powered_on(path: impl AsRef<Path>) -> bool {
|
|||
return true;
|
||||
};
|
||||
let Ok(state) =
|
||||
tokio::fs::read_to_string(format!("/sys/class/drm/{}/device/power_state", name)).await
|
||||
tokio::fs::read_to_string(format!("/sys/class/drm/{name}/device/power_state")).await
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
|
|
@ -201,120 +201,117 @@ impl Gpu {
|
|||
}
|
||||
|
||||
async fn app_list(&self, running_apps: &[RunningApp]) -> Option<Vec<Entry>> {
|
||||
match self.driver.as_ref().and_then(|s| s.to_str()) {
|
||||
Some("nvidia") => {
|
||||
// figure out bus path for calling nvidia-smi
|
||||
let mut sys_path = PathBuf::from("/sys/class/drm");
|
||||
sys_path.push(self.path.components().last()?.as_os_str());
|
||||
let buslink = std::fs::read_link(sys_path)
|
||||
.ok()?
|
||||
.components()
|
||||
.rev()
|
||||
.nth(2)?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
if let Some("nvidia") = self.driver.as_ref().and_then(|s| s.to_str()) {
|
||||
// figure out bus path for calling nvidia-smi
|
||||
let mut sys_path = PathBuf::from("/sys/class/drm");
|
||||
sys_path.push(self.path.components().next_back()?.as_os_str());
|
||||
let buslink = std::fs::read_link(sys_path)
|
||||
.ok()?
|
||||
.components()
|
||||
.rev()
|
||||
.nth(2)?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
let smi_output = match tokio::process::Command::new("nvidia-smi")
|
||||
.args(["pmon", "--id", &buslink, "--count", "1"])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
Ok(output) => {
|
||||
debug!(
|
||||
"smi returned error code {}: {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
return None;
|
||||
}
|
||||
Err(err) => {
|
||||
debug!("smi returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let smi_output = match tokio::process::Command::new("nvidia-smi")
|
||||
.args(["pmon", "--id", &buslink, "--count", "1"])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
Ok(output) => {
|
||||
debug!(
|
||||
"smi returned error code {}: {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
return None;
|
||||
}
|
||||
Err(err) => {
|
||||
debug!("smi returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
smi_output
|
||||
.lines()
|
||||
.filter(|line| {
|
||||
// smi shows an empty line filled with - when no app is running
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
components[1].trim().ne("-") && !line.starts_with('#')
|
||||
})
|
||||
.map(|line| {
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
let pid = components[1].trim();
|
||||
let process_name = components.last().unwrap().trim();
|
||||
Some(
|
||||
smi_output
|
||||
.lines()
|
||||
.filter(|line| {
|
||||
// smi shows an empty line filled with - when no app is running
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
components[1].trim().ne("-") && !line.starts_with('#')
|
||||
})
|
||||
.map(|line| {
|
||||
let components = line.split_whitespace().collect::<Vec<_>>();
|
||||
let pid = components[1].trim();
|
||||
let process_name = components.last().unwrap().trim();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == process_name)
|
||||
{
|
||||
Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
}
|
||||
} else {
|
||||
Entry {
|
||||
name: process_name.to_string(),
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
}
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == process_name)
|
||||
{
|
||||
Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let lsof_output = match tokio::process::Command::new("lsof")
|
||||
.args([OsStr::new("-t"), self.path.as_os_str()])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
||||
Err(err) => {
|
||||
debug!("lsof returned error code: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
lsof_output
|
||||
.lines()
|
||||
.filter_map(|pid| {
|
||||
let executable = std::fs::read_link(format!("/proc/{}/exe", pid))
|
||||
.ok()?
|
||||
.components()
|
||||
.last()?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == executable)
|
||||
{
|
||||
Some(Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
})
|
||||
} else {
|
||||
Some(Entry {
|
||||
name: executable,
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
})
|
||||
} else {
|
||||
Entry {
|
||||
name: process_name.to_string(),
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
let lsof_output = match tokio::process::Command::new("lsof")
|
||||
.args([OsStr::new("-t"), self.path.as_os_str()])
|
||||
.output()
|
||||
.await
|
||||
{
|
||||
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
||||
Err(err) => {
|
||||
debug!("lsof returned error code: {err}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(
|
||||
lsof_output
|
||||
.lines()
|
||||
.filter_map(|pid| {
|
||||
let executable = std::fs::read_link(format!("/proc/{pid}/exe"))
|
||||
.ok()?
|
||||
.components()
|
||||
.next_back()?
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
if let Some(application) = running_apps
|
||||
.iter()
|
||||
.find(|running_app| running_app.executable_name == executable)
|
||||
{
|
||||
Some(Entry {
|
||||
name: application.name.clone(),
|
||||
icon: application.icon.clone(),
|
||||
secondary: String::new(),
|
||||
})
|
||||
} else {
|
||||
Some(Entry {
|
||||
name: executable,
|
||||
icon: None,
|
||||
secondary: pid.to_string(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -325,14 +322,14 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
enumerator.match_sysname("card[0-9]*")?;
|
||||
let mut gpus = enumerator
|
||||
.scan_devices()?
|
||||
.filter(|device| {
|
||||
device
|
||||
.filter_map(|device| {
|
||||
if device
|
||||
.property_value("ID_SEAT")
|
||||
.map(|x| x.to_os_string())
|
||||
.unwrap_or_else(|| OsString::from("seat0"))
|
||||
== *seat.as_ref()
|
||||
})
|
||||
.flat_map(|device| {
|
||||
.unwrap_or_else(|| OsStr::new("seat0"))
|
||||
!= seat.as_ref()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let path = device.devnode().map(PathBuf::from)?;
|
||||
let node = DrmNode::from_path(&path).ok()?;
|
||||
if !node.has_render() {
|
||||
|
|
@ -340,11 +337,8 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
}
|
||||
|
||||
let boot_vga = if let Ok(Some(pci)) = device.parent_with_subsystem(Path::new("pci")) {
|
||||
if let Some(value) = pci.attribute_value("boot_vga") {
|
||||
value == "1"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
pci.attribute_value("boot_vga")
|
||||
.is_some_and(|value| value == "1")
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
|
@ -352,10 +346,10 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
let name = if let Some(parent) = device.parent() {
|
||||
let vendor = parent
|
||||
.property_value("SWITCHEROO_CONTROL_VENDOR_NAME")
|
||||
.or_else(|| parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
let name = parent
|
||||
.property_value("SWITCHEROO_CONTROL_PRODUCT_NAME")
|
||||
.or_else(|| parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
|
||||
if vendor.is_none() && name.is_none() {
|
||||
String::from("Unknown GPU")
|
||||
|
|
@ -374,7 +368,7 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
let driver = loop {
|
||||
if let Some(dev) = device {
|
||||
if dev.driver().is_some() {
|
||||
break dev.driver().map(std::ffi::OsStr::to_os_string);
|
||||
break dev.driver().map(OsStr::to_os_string);
|
||||
} else {
|
||||
device = dev.parent();
|
||||
}
|
||||
|
|
@ -412,8 +406,8 @@ fn all_gpus<S: AsRef<str>>(seat: S) -> io::Result<Vec<Gpu>> {
|
|||
})
|
||||
})
|
||||
})
|
||||
.or_else(|| gpus.iter().position(|gpu| gpu.boot_vga))
|
||||
.or_else(|| (gpus.len() == 1).then_some(0))
|
||||
.or(gpus.iter().position(|gpu| gpu.boot_vga))
|
||||
.or((gpus.len() == 1).then_some(0))
|
||||
{
|
||||
gpus[primary_idx].primary = true;
|
||||
}
|
||||
|
|
@ -487,10 +481,10 @@ async fn start_listening(
|
|||
let name = if let Some(parent) = device.parent() {
|
||||
let vendor = parent
|
||||
.property_value("SWITCHEROO_CONTROL_VENDOR_NAME")
|
||||
.or_else(|| parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_VENDOR_FROM_DATABASE"));
|
||||
let name = parent
|
||||
.property_value("SWITCHEROO_CONTROL_PRODUCT_NAME")
|
||||
.or_else(|| parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
.or(parent.property_value("ID_MODEL_FROM_DATABASE"));
|
||||
|
||||
if vendor.is_none() && name.is_none() {
|
||||
String::from("Unknown GPU")
|
||||
|
|
@ -509,7 +503,7 @@ async fn start_listening(
|
|||
let driver = loop {
|
||||
if let Some(dev) = device {
|
||||
if dev.driver().is_some() {
|
||||
break dev.driver().map(std::ffi::OsStr::to_os_string);
|
||||
break dev.driver().map(OsStr::to_os_string);
|
||||
} else {
|
||||
device = dev.parent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue