Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: reduce Unknown app names and improve icon lookup on Windows

Louis Beaumont07a0f57adbaf
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/icons.rs b/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
index 3d58a2ef1..c256c03fe 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
@@ -135,8 +135,31 @@ fn get_exe_by_reg_key(app_name: &str) -> Option<String> {
use winreg::enums::*;
use winreg::RegKey;
+ let app_lower = app_name.to_lowercase();
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
+
+ // First try App Paths direct lookup (e.g. "wezterm-gui.exe" subkey)
+ let app_paths = [
+ "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",
+ "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths",
+ ];
+ for path in &app_paths {
+ for root in [&hklm, &hkcu] {
+ // Try exact exe name as subkey (e.g. "wezterm-gui.exe")
+ let exe_key = format!("{}.exe", app_name);
+ if let Ok(app_key) = root.open_subkey(format!("{}\\{}", path, exe_key)) {
+ if let Ok(exe_path) = app_key.get_value::<String, _>("") {
+ let cleaned = exe_path.trim_matches('"').to_string();
+ if !cleaned.is_empty() && std::path::Path::new(&cleaned).exists() {
+ return Some(cleaned);
+ }
+ }
+ }
+ }
+ }
+
+ // Then search Uninstall + App Paths for DisplayName match
let reg_paths = [
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
"Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
@@ -148,32 +171,55 @@ fn get_exe_by_reg_key(app_name: &str) -> Option<String> {
let keys = [hklm.open_subkey(path), hkcu.open_subkey(path)];
for key in keys.iter().filter_map(|k| k.as_ref().ok()) {
for subkey in key.enum_keys().filter_map(Result::ok) {
+ let subkey_lower = subkey.to_lowercase();
if let Ok(app_key) = key.open_subkey(&subkey) {
- if let Ok(display_name) = app_key.get_value::<String, _>("DisplayName") {
- if display_name
- .to_lowercase()
- .contains(&app_name.to_lowercase())
- {
- if let Ok(path) = app_key.get_value::<String, _>("DisplayIcon") {
- let cleaned_path = path
- .split(',')
- .next()
- .unwrap_or(&path)
- .to_string()
- .trim_matches('"')
- .to_string();
+ // Match on DisplayName or subkey name (App Paths uses exe name)
+ let display_match = app_key
+ .get_value::<String, _>("DisplayName")
+ .map(|d| d.to_lowercase().contains(&app_lower))
+ .unwrap_or(false);
+ let subkey_match = subkey_lower.contains(&app_lower)
+ || app_lower.contains(&subkey_lower.trim_end_matches(".exe"));
+
+ if display_match || subkey_match {
+ if let Ok(path) = app_key.get_value::<String, _>("DisplayIcon") {
+ let cleaned_path = path
+ .split(',')
+ .next()
+ .unwrap_or(&path)
+ .to_string()
+ .trim_matches('"')
+ .to_string();
+ if std::path::Path::new(&cleaned_path).exists() {
return Some(cleaned_path);
- } else if let Ok(path) = app_key.get_value::<String, _>("(default)") {
- let cleaned_path = path
- .split(',')
- .next()
- .unwrap_or(&path)
- .to_string()
- .trim_matches('"')
- .to_string();
+ }
+ }
+ // App Paths uses default value ""
+ if let Ok(path) = app_key.get_value::<String, _>("") {
+ let cleaned_path = path.trim_matches('"').to_string();
+ if !cleaned_path.is_empty()
+ && std::path::Path::new(&cleaned_path).exists()
+ {
return Some(cleaned_path);
}
}
+ if let Ok(path) = app_key.get_value::<String, _>("InstallLocation") {
+ let install_dir = std::path::Path::new(path.trim_matches('"'));
+ if install_dir.is_dir() {
+ // Look for any exe matching app_name in install dir
+ if let Ok(entries) = std::fs::read_dir(install_dir) {
+ for entry in entries.flatten() {
+ let fname = entry.file_name().to_string_lossy().to_lowercase();
+ if fname.ends_with(".exe") && fname.contains(&app_lower)
+ {
+ return Some(
+ entry.path().to_string_lossy().to_string(),
+ );
+ }
+ }
+ }
+ }
+ }
}
}
}
@@ -197,6 +243,38 @@ fn powershell_exe() -> std::path::PathBuf {
async fn get_exe_from_potential_path(app_name: &str) -> Option<String> {
const CREATE_NO_WINDOW: u32 = 0x08000000;
let app_name = app_name.strip_suffix(".exe").unwrap_or(&app_name);
+
+ // Try direct path in Program Files first (fast, no PowerShell)
+ let program_dirs = [
+ r"C:\Program Files",
+ r"C:\Program Files (x86)",
+ ];
+ let app_lower = app_name.to_lowercase();
+ for dir in &program_dirs {
+ let base = std::path::Path::new(dir);
+ if let Ok(entries) = std::fs::read_dir(base) {
+ for entry in entries.flatten() {
+ let folder_name = entry.file_name().to_string_lossy().to_lowercase();
+ if folder_name.contains(&app_lower) || app_lower.contains(&folder_name) {
+ // Found matching folder, look for exe inside
+ if let Ok(sub_entries) = std::fs::read_dir(entry.path()) {
+ for sub in sub_entries.flatten() {
+ let fname = sub.file_name().to_string_lossy().to_lowercase();
+ if fname.ends_with(".exe") && (fname.contains(&app_lower) || fname.contains("gui")) {
+ return Some(sub.path().to_string_lossy().to_string());
+ }
+ }
+ }
+ // Also check for direct exe match
+ let direct_exe = entry.path().join(format!("{}.exe", app_name));
+ if direct_exe.exists() {
+ return Some(direct_exe.to_string_lossy().to_string());
+ }
+ }
+ }
+ }
+ }
+
let potential_paths = [
(
r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs",
diff --git a/crates/screenpipe-vision/src/capture_screenshot_by_window.rs b/crates/screenpipe-vision/src/capture_screenshot_by_window.rs
index 028ee6018..3f5ef7ab6 100644
--- a/crates/screenpipe-vision/src/capture_screenshot_by_window.rs
+++ b/crates/screenpipe-vision/src/capture_screenshot_by_window.rs
@@ -821,13 +821,66 @@ fn extract_window_data_xcap(window: XcapWindow) -> Option<WindowData> {
}
}
+#[cfg(target_os = "windows")]
+fn get_process_exe_name(pid: u32) -> Option<String> {
+ // Use raw FFI to avoid windows-core version conflicts with xcap
+ #[link(name = "kernel32")]
+ extern "system" {
+ fn OpenProcess(dwDesiredAccess: u32, bInheritHandle: i32, dwProcessId: u32) -> isize;
+ fn CloseHandle(hObject: isize) -> i32;
+ }
+ #[link(name = "psapi")]
+ extern "system" {
+ fn GetModuleFileNameExW(
+ hProcess: isize,
+ hModule: isize,
+ lpFilename: *mut u16,
+ nSize: u32,
+ ) -> u32;
+ }
+
+ const PROCESS_QUERY_INFORMATION: u32 = 0x0400;
+ const PROCESS_VM_READ: u32 = 0x0010;
+ const PROCESS_QUERY_LIMITED_INFORMATION: u32 = 0x1000;
+
+ unsafe {
+ // Try full access first, fall back to limited (handles elevated processes)
+ let mut handle =
+ OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, pid);
+ if handle == 0 {
+ handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);
+ }
+ if handle == 0 {
+ return None;
+ }
+
+ let mut buf = [0u16; 260];
+ let len = GetModuleFileNameExW(handle, 0, buf.as_mut_ptr(), buf.len() as u32);
+ CloseHandle(handle);
+
+ if len == 0 {
+ return None;
+ }
+
+ let path = String::from_utf16_lossy(&buf[..len as usize]);
+
+ // Extract filename without .exe
+ let filename = path.rsplit('\\').next().unwrap_or(&path);
+ let name = filename.strip_suffix(".exe").unwrap_or(filename);
+ if name.is_empty() {
+ return None;
+ }
+ Some(name.to_string())
+ }
+}
+
#[cfg(not(target_os = "macos"))]
fn get_all_windows() -> Result<Vec<WindowData>, Box<dyn Error>> {
let windows = Window::all()?;
Ok(windows
.into_iter()
.filter_map(|window| {
- let app_name = match window.app_name() {
+ let mut app_name = match window.app_name() {
Ok(name) => name.to_string(),
Err(e) => {
debug!("Failed to get app_name for window: {}", e);
@@ -835,6 +888,18 @@ fn get_all_windows() -> Result<Vec<WindowData>, Box<dyn Error>> {
}
};
+ // On Windows, xcap returns empty string when OpenProcess fails
+ // (elevated/system processes). Fall back to exe filename.
+ #[cfg(target_os = "windows")]
+ if app_name.is_empty() {
+ if let Some(pid) = window.pid().ok() {
+ if let Some(exe_name) = get_process_exe_name(pid as u32) {
+ debug!("app_name was empty, using exe name: {}", exe_name);
+ app_name = exe_name;
+ }
+ }
+ }
+
let title = match window.title() {
Ok(title) => title.to_string(),
Err(e) => {