battery/dgpu: Fix name of hotplugged gpus
This commit is contained in:
parent
89986d8268
commit
1ad07dc2f3
1 changed files with 20 additions and 8 deletions
|
|
@ -418,17 +418,29 @@ async fn start_listening(
|
||||||
// New device
|
// New device
|
||||||
EventType::Add => {
|
EventType::Add => {
|
||||||
if let Some(path) = event.devnode() {
|
if let Some(path) = event.devnode() {
|
||||||
let name = if let Ok(Some(pci)) = event.device().parent_with_subsystem(Path::new("pci")) {
|
let device = event.device();
|
||||||
if let Some(value) = pci.attribute_value("ID_MODEL_FROM_DATABASE") {
|
let name = if let Some(parent) = device.parent() {
|
||||||
value.to_string_lossy().into_owned()
|
let vendor = parent
|
||||||
|
.property_value("SWITCHEROO_CONTROL_VENDOR_NAME")
|
||||||
|
.or_else(|| 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"));
|
||||||
|
|
||||||
|
if vendor.is_none() && name.is_none() {
|
||||||
|
String::from("Unknown GPU")
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"{} {}",
|
||||||
|
vendor.map(|s| s.to_string_lossy()).unwrap_or_default(),
|
||||||
|
name.map(|s| s.to_string_lossy()).unwrap_or_default()
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String::from("Unknown")
|
String::from("Unknown GPU")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String::from("Unknown")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut device = Some(event.device());
|
let mut device = Some(device);
|
||||||
let driver = loop {
|
let driver = loop {
|
||||||
if let Some(dev) = device {
|
if let Some(dev) = device {
|
||||||
if dev.driver().is_some() {
|
if dev.driver().is_some() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue