From bee751e16b83b8abae046172d24796c657646108 Mon Sep 17 00:00:00 2001 From: Rerence1016 Date: Fri, 1 Aug 2025 20:22:42 +0800 Subject: [PATCH] feat(exe): add regex, find and use exe name for proton/wine processes in ui --- ui/Cargo.lock | 1 + ui/Cargo.toml | 1 + ui/src/utils.rs | 34 +++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ui/Cargo.lock b/ui/Cargo.lock index 12b4239..6ca026a 100644 --- a/ui/Cargo.lock +++ b/ui/Cargo.lock @@ -690,6 +690,7 @@ dependencies = [ "libadwaita", "proc-maps", "procfs", + "regex", "serde", "toml 0.9.2", ] diff --git a/ui/Cargo.toml b/ui/Cargo.toml index f8593f9..f71a00b 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -11,6 +11,7 @@ toml = "0.9.2" anyhow = "1.0" procfs = "0.17.0" proc-maps = "0.4.0" +regex = "1.11.1" [build-dependencies] glib-build-tools = "0.21.0" diff --git a/ui/src/utils.rs b/ui/src/utils.rs index 190b503..0d6e5d5 100644 --- a/ui/src/utils.rs +++ b/ui/src/utils.rs @@ -1,27 +1,51 @@ use procfs::{process, ProcResult}; +use regex::Regex; pub fn find_vulkan_processes() -> ProcResult> { + + // Extract just .exe name from a running Wine or Proton process + let pattern = Regex::new(r"[-\w\s\.()\[\]!@]*(\.[Ee][Xx][Ee])").unwrap(); + let mut processes = Vec::new(); let apps = process::all_processes()?; + for app in apps { - let Ok(prc) = app else { continue; }; + let Ok(process) = app else { continue; }; // ensure vulkan is loaded - let Ok(maps) = proc_maps::get_process_maps(prc.pid()) else { + let Ok(maps) = proc_maps::get_process_maps(process.pid()) else { continue; }; + let result = maps.iter() .filter_map(|map| map.filename()) .map(|filename| filename.to_string_lossy().to_string()) .any(|filename| filename.to_lowercase().contains("vulkan")); + if !result { continue; } // format process information - let pid = prc.pid(); - let name = prc.stat()?.comm; - let process_info = format!("PID {}: {}", pid, name); + let pid = process.pid(); + let name: String; + let cmdline = process.cmdline()?.join(" "); + + // If this is a Proton or Wine process with .exe, + // then extract just the .exe name with RegEx + if cmdline.contains(".exe") { + name = pattern.find(&cmdline) + .unwrap() + .as_str() + .to_string(); + } else { + + // If just a normal Linux process, then use + // the normal name + name = process.stat()?.comm; + } + + let process_info = format!("PID {pid}: {name}"); processes.push((process_info, name)); }