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
fix: infinite loop of powershell & use icon cache with localforage and limit powershell process (#802)
tribhuwan4d29fe46fcfb
diff --git a/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx b/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsxindex bbf99e9ab..13c966c58 100644--- a/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx+++ b/screenpipe-app-tauri/components/timeline/timeline-dock-section.tsx@@ -1,3 +1,4 @@+import localforage from "localforage";import React, { useEffect, useState, useCallback, useMemo } from "react";import { platform } from "@tauri-apps/plugin-os";import { invoke } from "@tauri-apps/api/core";@@ -37,6 +38,7 @@ export function TimelineIconsSection({const os = platform();const [iconCache, setIconCache] = useState<{ [key: string]: string }>({});const [selectedApp, setSelectedApp] = useState<ProcessedBlock | null>(null);+ const [iconInvocationCount, setIconInvocationCount] = useState<{ [key: string]: number }>({});const { setSelectionRange } = useTimelineSelection();// Get the visible time range@@ -175,6 +177,17 @@ export function TimelineIconsSection({try {if (iconCache[appName]) return;+ const cachedIcon = await localforage.getItem<string>(`icon-${appName}`);+ if (cachedIcon) {+ setIconCache((prev) => ({+ ...prev,+ [appName]: cachedIcon,+ }));+ return;+ }++ if (iconInvocationCount[appName] >= 100) return;+const icon = await invoke<{ base64: string; path: string } | null>("get_app_icon",{ appName, appPath }@@ -186,13 +199,20 @@ export function TimelineIconsSection({...prev,[appName]: icon.base64,}));++ await localforage.setItem(`icon-${appName}`, icon.base64);++ setIconInvocationCount((prev) => ({+ ...prev,+ [appName]: (prev[appName] || 0) + 1,+ }));}} catch (error) {console.error(`failed to load icon for ${appName}:`, error);// Fail silently - the UI will just not show an icon}},- [iconCache]+ [iconCache, iconInvocationCount]);useEffect(() => {diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex b92cbf4a4..4d9ca9efd 100644--- a/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -95,6 +95,7 @@ base64 = "0.22.1"[target.'cfg(target_os = "windows")'.dependencies]winreg = "0.52.0"+lazy_static = "1.5.0"windows-icons = { git = "https://github.com/tribhuwan-kumar/windows-icons.git" }[target.'cfg(target_os = "linux")'.dependencies]diff --git a/screenpipe-app-tauri/src-tauri/src/icons.rs b/screenpipe-app-tauri/src-tauri/src/icons.rsindex 99333a49b..00d64a68a 100644--- a/screenpipe-app-tauri/src-tauri/src/icons.rs+++ b/screenpipe-app-tauri/src-tauri/src/icons.rs@@ -73,6 +73,17 @@ pub async fn get_app_icon(}}+#[cfg(target_os = "windows")]+use tokio::sync::Semaphore;+#[cfg(target_os = "windows")]+use std::sync::Arc;+#[cfg(target_os = "windows")]+use lazy_static::lazy_static;+#[cfg(target_os = "windows")]+lazy_static! {+ static ref SEMAPHORE: Arc<Semaphore> = Arc::new(Semaphore::new(5));+}+#[tauri::command]#[cfg(target_os = "windows")]pub async fn get_app_icon(@@ -148,6 +159,7 @@ fn get_exe_by_reg_key(#[cfg(target_os = "windows")]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);let potential_paths = [(r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs", true),@@ -172,9 +184,15 @@ async fn get_exe_from_potential_path(app_name: &str) -> Option<String>{)};+ let _permit = SEMAPHORE.acquire().await.unwrap();+let output = tokio::process::Command::new("powershell")+ .arg("-NoProfile")+ .arg("-WindowStyle")+ .arg("hidden").arg("-Command").arg(command)+ .creation_flags(CREATE_NO_WINDOW).output().await.ok()?;@@ -195,15 +213,22 @@ async fn get_exe_by_appx() -> Option<String> {use std::str;+ const CREATE_NO_WINDOW: u32 = 0x08000000;let app_name = app_name.strip_suffix(".exe").unwrap_or(&app_name);let app_name_withoutspace = app_name.replace(" ", "");+ let _permit = SEMAPHORE.acquire().await.unwrap();+let output = tokio::process::Command::new("powershell")+ .arg("-NoProfile")+ .arg("-WindowStyle")+ .arg("hidden").arg("-Command").arg(format!(r#"Get-AppxPackage | Where-Object {{ $_.Name -like "*{}*" }}"#,app_name_withoutspace))+ .creation_flags(CREATE_NO_WINDOW).output().await.expect("failed to execute powershell command");@@ -220,6 +245,9 @@ async fn get_exe_by_appx(.map(str::trim)?;let exe_output = tokio::process::Command::new("powershell")+ .arg("-NoProfile")+ .arg("-WindowStyle")+ .arg("hidden").arg("-Command").arg(format!(r#"@@ -228,6 +256,7 @@ async fn get_exe_by_appx(package_name,app_name_withoutspace))+ .creation_flags(CREATE_NO_WINDOW).output().await.ok()?;@@ -240,6 +269,9 @@ async fn get_exe_by_appx(}// second attempt with space if the first attempt couldn't find exelet exe_output = tokio::process::Command::new("powershell")+ .arg("-NoProfile")+ .arg("-WindowStyle")+ .arg("hidden").arg("-Command").arg(format!(r#"@@ -248,6 +280,7 @@ async fn get_exe_by_appx(package_name,app_name))+ .creation_flags(CREATE_NO_WINDOW).output().await.ok()?;