feat(src/hardware): add logging for detected NVIDIA GPU and refactor command calls

Add `info!` logging when a NVIDIA GPU is discovered via `lspci`, enhancing debug visibility. Refactor the `lspci` and `xrandr` command constructions into multi‑line style for consistency and prepare a regex for future AMD GPU name detection.

- New Features: Log GPU detection with `info!` macro.
- Enhancements: Refactor command calls for readability; introduce regex preparation for AMD detection.
- Bug Fixes: None.
This commit is contained in:
sankalp committed 2026-03-12 00:27:57 +05:45
1 parent d67eae94d9
commit e8f6c69638
1 file changed
+10 -3
+10 -3
View File
@@ -21,11 +21,15 @@ pub fn get_current_mode() -> String {
}
pub fn get_nvidia_gpu_pci_bus() -> String {
let output = Command::new("lspci").output().expect("Failed to execute lspci");
let output = Command::new("lspci")
.output()
.expect("Failed to execute lspci");
let lspci_output = String::from_utf8_lossy(&output.stdout);
for line in lspci_output.lines() {
if line.contains("NVIDIA") && (line.contains("VGA compatible controller") || line.contains("3D controller")) {
if line.contains("NVIDIA")
&& (line.contains("VGA compatible controller") || line.contains("3D controller"))
{
let pci_bus_id_raw = line.split_whitespace().next().unwrap();
let pci_bus_id = pci_bus_id_raw.replace("0000:", "");
info!("Found Nvidia GPU at {}", pci_bus_id);
@@ -75,7 +79,10 @@ pub fn get_amd_igpu_name() -> Option<String> {
return None;
}
let output = Command::new("xrandr").arg("--listproviders").output().ok()?;
let output = Command::new("xrandr")
.arg("--listproviders")
.output()
.ok()?;
let xrandr_output = String::from_utf8_lossy(&output.stdout);
let pattern = Regex::new(r"name:.*(ATI|AMD|AMD/ATI)").unwrap();