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 Windows crash when resolving app icons

Divanshu73128f438678
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/icons.rs b/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
index 01f17d932..3d58a2ef1 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/icons.rs
@@ -182,6 +182,17 @@ fn get_exe_by_reg_key(app_name: &str) -> Option<String> {
None
}
+#[cfg(target_os = "windows")]
+fn powershell_exe() -> std::path::PathBuf {
+ let system_root =
+ std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".to_string());
+ std::path::PathBuf::from(system_root)
+ .join("System32")
+ .join("WindowsPowerShell")
+ .join("v1.0")
+ .join("powershell.exe")
+}
+
#[cfg(target_os = "windows")]
async fn get_exe_from_potential_path(app_name: &str) -> Option<String> {
const CREATE_NO_WINDOW: u32 = 0x08000000;
@@ -212,7 +223,7 @@ 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")
+ let output = tokio::process::Command::new(powershell_exe())
.arg("-NoProfile")
.arg("-WindowStyle")
.arg("hidden")
@@ -243,7 +254,7 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
let _permit = SEMAPHORE.acquire().await.unwrap();
- let output = tokio::process::Command::new("powershell")
+ let output = tokio::process::Command::new(powershell_exe())
.arg("-NoProfile")
.arg("-WindowStyle")
.arg("hidden")
@@ -255,7 +266,7 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
.creation_flags(CREATE_NO_WINDOW)
.output()
.await
- .expect("failed to execute powershell command");
+ .ok()?;
if !output.status.success() {
return None;
@@ -268,7 +279,7 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
.and_then(|line| line.split(':').nth(1))
.map(str::trim)?;
- let exe_output = tokio::process::Command::new("powershell")
+ let exe_output = tokio::process::Command::new(powershell_exe())
.arg("-NoProfile")
.arg("-WindowStyle")
.arg("hidden")
@@ -292,7 +303,7 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
}
}
// second attempt with space if the first attempt couldn't find exe
- let exe_output = tokio::process::Command::new("powershell")
+ let exe_output = tokio::process::Command::new(powershell_exe())
.arg("-NoProfile")
.arg("-WindowStyle")
.arg("hidden")