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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: add icon in timeline for windows (#706)
tribhuwanfa05865cf3a5
diff --git a/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx b/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsxindex 0a9289834..d9864e74f 100644--- a/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx+++ b/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx@@ -172,10 +172,6 @@ export function TimelineIconsSection({const loadAppIcon = useCallback(async (appName: string, appPath?: string) => {try {- // Check platform first to avoid unnecessary invokes- const p = platform();- if (p !== "macos") return; // Early return for unsupported platforms-if (iconCache[appName]) return;const icon = await invoke<{ base64: string; path: string } | null>(@@ -200,8 +196,6 @@ export function TimelineIconsSection({useEffect(() => {const loadIcons = async () => {- const p = platform();- if (p !== "macos") return;// Load icons for unique app names onlyprocessedBlocks.forEach((block) => {diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 30f8cdf0e..5bcc514c4 100644--- a/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -93,6 +93,10 @@ cocoa = "0.26.0"objc = "0.2.7"base64 = "0.22.1"+[target.'cfg(target_os = "windows")'.dependencies]+winreg = "0.52.0"+windows-icons = { git = "https://github.com/tribhuwan-kumar/windows-icons.git" }+[features]cudart = []metal = []diff --git a/screenpipe-app-tauri/src-tauri/src/icons.rs b/screenpipe-app-tauri/src-tauri/src/icons.rsindex eb4740f06..7a21f5618 100644--- a/screenpipe-app-tauri/src-tauri/src/icons.rs+++ b/screenpipe-app-tauri/src-tauri/src/icons.rs@@ -79,10 +79,184 @@ pub async fn get_app_icon(app_name: &str,app_path: Option<String>,) -> Result<Option<AppIcon>, String> {- // Windows: Extract icon from exe using Shell32- // Convert to base64- // Return AppIcon struct- Ok(None)+ use windows_icons::get_icon_base64_by_path;++ async fn find_exe_path(app_name: &str) -> Option<String> {+ if let Some(path) = get_exe_by_reg_key(app_name) {+ return Some(path);+ }+ if let Some(path) = get_exe_by_appx(app_name).await {+ return Some(path);+ }+ if let Some(path) = get_exe_from_potential_path(app_name).await {+ return Some(path);+ }+ None+ }++ let path = match app_path {+ Some(p) => p,+ None => find_exe_path(app_name).await.ok_or_else(|| "app_path is None and could not find executable path".to_string())?,+ };++ let base64 = get_icon_base64_by_path(&path).await.map_err(|e| e.to_string())?;++ Ok(Some(AppIcon {+ base64,+ path: Some(path),+ }))+}++fn get_exe_by_reg_key(+ app_name: &str+) -> Option<String> {+ use winreg::RegKey;+ use winreg::enums::*;++ let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);+ let hkcu = RegKey::predef(HKEY_CURRENT_USER);+ let reg_paths = [+ "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",+ "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall",+ "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",+ "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths",+ ];++ for path in ®_paths {+ 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) {+ 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();+ 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();+ return Some(cleaned_path);+ }+ }+ }+ }+ }+ }+ }+ None+}+++async fn get_exe_from_potential_path(app_name: &str) -> Option<String>{+ let app_name = app_name.strip_suffix(".exe").unwrap_or(&app_name);+ let potential_paths = [+ (r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", true),+ (r"C:\Windows\", false),+ ];+ for (path, recursive) in &potential_paths {+ let command = if *recursive {+ format!(+ r#"+ Get-ChildItem -Path "{}" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}+ "#,+ path,+ app_name+ )+ } else {+ format!(+ r#"+ Get-ChildItem -Path "{}" -Filter "*{}*.exe" | ForEach-Object {{ $_.FullName }}+ "#,+ path,+ app_name+ )+ };++ let output = tokio::process::Command::new("powershell")+ .arg("-Command")+ .arg(command)+ .output()+ .await+ .ok()?;++ if output.status.success() {+ let stdout = std::str::from_utf8(&output.stdout).ok()?;+ if !stdout.is_empty() {+ return stdout.lines().next().map(str::to_string);+ }+ }+ }+ None+}++async fn get_exe_by_appx(+ app_name: &str+) -> Option<String> {+ use std::str;++ let app_name = app_name.strip_suffix(".exe").unwrap_or(&app_name);+ let app_name_withoutspace = app_name.replace(" ", "");++ let output = tokio::process::Command::new("powershell")+ .arg("-Command")+ .arg(format!(+ r#"Get-AppxPackage | Where-Object {{ $_.Name -like "*{}*" }}"#,+ app_name_withoutspace+ ))+ .output()+ .await+ .expect("failed to execute powershell command");++ if !output.status.success() {+ return None+ }++ let stdout = str::from_utf8(&output.stdout).ok()?;+ let package_name = stdout+ .lines()+ .find(|line| line.contains("PackageFullName"))+ .and_then(|line| line.split(':').nth(1))+ .map(str::trim)?;++ let exe_output = tokio::process::Command::new("powershell")+ .arg("-Command")+ .arg(format!(+ r#"+ Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}+ "#,+ package_name,+ app_name_withoutspace+ ))+ .output()+ .await+ .ok()?;++ if exe_output.status.success() {+ let exe_stdout = str::from_utf8(&exe_output.stdout).ok()?;+ if !exe_stdout.is_empty() {+ return exe_stdout.lines().next().map(str::to_string);+ }+ }+ // second attempt with space if the first attempt couldn't find exe+ let exe_output = tokio::process::Command::new("powershell")+ .arg("-Command")+ .arg(format!(+ r#"+ Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}+ "#,+ package_name,+ app_name+ ))+ .output()+ .await+ .ok()?;++ if exe_output.status.success() {+ let exe_stdout = str::from_utf8(&exe_output.stdout).ok()?;+ if !exe_stdout.is_empty() {+ return exe_stdout.lines().next().map(str::to_string);+ }+ }+ None}#[tauri::command]