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

release-app fix analytics and automatic update of pipes, fix watchdog windows node process

Louis Beaumont90e6a46f60ba
diff --git a/screenpipe-app-tauri/components/pipe-store.tsx b/screenpipe-app-tauri/components/pipe-store.tsx
index c97a06d91..f7f01ee31 100644
--- a/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/screenpipe-app-tauri/components/pipe-store.tsx
@@ -74,12 +74,18 @@ export const PipeStore: React.FC = () => {
}, 1000); // Debounce for 1 second
return () => clearTimeout(timeoutId);
- }, [searchQuery, filteredPipes.length])
+ }, [searchQuery, filteredPipes.length]);
- listen("update-all-pipes", async () => {
- if (!checkLogin(settings.user, false)) return;
- await handleUpdateAllPipes(true)
- });
+ useEffect(() => {
+ const unsubscribePromise = listen("update-all-pipes", async () => {
+ if (!checkLogin(settings.user, false)) return;
+ await handleUpdateAllPipes(true);
+ });
+
+ return () => {
+ unsubscribePromise.then((unsubscribe) => unsubscribe());
+ };
+ }, []);
const fetchStorePlugins = async () => {
try {
@@ -469,7 +475,7 @@ export const PipeStore: React.FC = () => {
posthog.capture("update_all_pipes", {});
- let t
+ let t;
if (!delayToast) {
t = toast({
title: "checking for updates",
diff --git a/screenpipe-app-tauri/lib/hooks/use-health-check.tsx b/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
index e16085983..77fb0f212 100644
--- a/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-health-check.tsx
@@ -1,6 +1,5 @@
import { useState, useEffect, useCallback, useRef } from "react";
import { debounce } from "lodash";
-import posthog from "posthog-js";
interface HealthCheckResponse {
status: string;
@@ -40,23 +39,6 @@ interface HealthCheckHook {
debouncedFetchHealth: () => Promise<void>;
}
-const POSTHOG_RATE_LIMIT_HOURS = 1; // adjust this value as needed
-
-function shouldSendPosthogEvent(eventName: string): boolean {
- const lastSentKey = `last_posthog_${eventName}`;
- const lastSent = localStorage.getItem(lastSentKey);
- const now = Date.now();
-
- if (
- !lastSent ||
- now - parseInt(lastSent) > POSTHOG_RATE_LIMIT_HOURS * 60 * 60 * 1000
- ) {
- localStorage.setItem(lastSentKey, now.toString());
- return true;
- }
- return false;
-}
-
export function useHealthCheck() {
const [health, setHealth] = useState<HealthCheckResponse | null>(null);
const [isServerDown, setIsServerDown] = useState(false);
@@ -95,29 +77,9 @@ export function useHealthCheck() {
previousHealthStatus.current === "healthy"
) {
unhealthyTransitionsRef.current += 1;
-
- if (shouldSendPosthogEvent("health_check_unhealthy")) {
- posthog.capture("health_check_unhealthy", {
- frame_status: data.frame_status,
- audio_status: data.audio_status,
- ui_status: data.ui_status,
- message: data.message,
- transitions_since_last_event: unhealthyTransitionsRef.current,
- });
- unhealthyTransitionsRef.current = 0;
- }
}
previousHealthStatus.current = data.status;
-
- if (data.status === "unhealthy") {
- posthog.capture("health_check_unhealthy", {
- frame_status: data.frame_status,
- audio_status: data.audio_status,
- ui_status: data.ui_status,
- message: data.message,
- });
- }
};
ws.onerror = (event) => {
@@ -134,9 +96,6 @@ export function useHealthCheck() {
message: error.message,
};
setHealth(errorHealth);
- posthog.capture("health_check_error", {
- error: error.message,
- });
setIsServerDown(true);
setIsLoading(false);
if (!retryIntervalRef.current) {
@@ -159,7 +118,7 @@ export function useHealthCheck() {
setHealth(errorHealth);
setIsServerDown(true);
if (!retryIntervalRef.current) {
- retryIntervalRef.current = setInterval(fetchHealth, 2000)
+ retryIntervalRef.current = setInterval(fetchHealth, 2000);
}
};
}, []);
@@ -196,4 +155,3 @@ export function useHealthCheck() {
debouncedFetchHealth,
} as HealthCheckHook;
}
-
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 8b5b5dab8..998102bc2 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -5289,7 +5289,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "0.32.5"
+version = "0.32.6"
dependencies = [
"anyhow",
"async-stream",
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 84acb7397..6a4ffdbc3 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.32.6"
+version = "0.32.7"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-app-tauri/src-tauri/src/analytics.rs b/screenpipe-app-tauri/src-tauri/src/analytics.rs
index be5afdca9..fc13ee47c 100755
--- a/screenpipe-app-tauri/src-tauri/src/analytics.rs
+++ b/screenpipe-app-tauri/src-tauri/src/analytics.rs
@@ -29,14 +29,15 @@ impl AnalyticsManager {
interval_hours: u64,
local_api_base_url: String,
screenpipe_dir_path: PathBuf,
+ analytics_enabled: bool,
) -> Self {
Self {
client: Client::new(),
posthog_api_key,
distinct_id,
email,
- interval: Duration::from_secs(interval_hours * 3600),
- enabled: Arc::new(Mutex::new(!cfg!(debug_assertions))),
+ interval: Duration::from_secs(interval_hours * 36),
+ enabled: Arc::new(Mutex::new(analytics_enabled)),
api_host: "https://eu.i.posthog.com".to_string(),
local_api_base_url,
screenpipe_dir_path,
@@ -72,23 +73,23 @@ impl AnalyticsManager {
});
// Add disk usage information
- if let Ok(Some(disk_usage)) = crate::disk_usage::disk_usage(&self.screenpipe_dir_path).await
- {
+ let disk_usage_result = crate::disk_usage::disk_usage(&self.screenpipe_dir_path).await;
+
+ if let Ok(Some(disk_usage)) = disk_usage_result {
if let Some(payload_props) = payload["properties"].as_object_mut() {
- payload_props.extend(
- json!({
- "disk_total_data_size": disk_usage.total_data_size,
- "disk_total_cache_size": disk_usage.total_cache_size,
- "disk_available_space": disk_usage.avaiable_space,
- "disk_media_videos_size": disk_usage.media.videos_size,
- "disk_media_audios_size": disk_usage.media.audios_size,
- "disk_total_pipes_size": disk_usage.pipes.total_pipes_size,
- })
- .as_object()
- .unwrap()
- .clone(),
- );
+ let disk_data = json!({
+ "disk_total_data_size": disk_usage.total_data_size,
+ "disk_total_cache_size": disk_usage.total_cache_size,
+ "disk_available_space": disk_usage.avaiable_space,
+ "disk_media_videos_size": disk_usage.media.videos_size,
+ "disk_media_audios_size": disk_usage.media.audios_size,
+ "disk_total_pipes_size": disk_usage.pipes.total_pipes_size,
+ });
+ warn!("disk data to add: {:?}", disk_data);
+ payload_props.extend(disk_data.as_object().unwrap().clone());
}
+ } else {
+ warn!("failed to get disk usage: {:?}", disk_usage_result);
}
if let Some(props) = properties {
@@ -97,6 +98,7 @@ impl AnalyticsManager {
}
}
+
let response = self.client.post(posthog_url).json(&payload).send().await?;
if !response.status().is_success() {
@@ -207,19 +209,12 @@ pub fn start_analytics(
interval_hours: u64,
local_api_base_url: String,
screenpipe_dir_path: PathBuf,
+ analytics_enabled: bool,
) -> Result<Arc<AnalyticsManager>, Box<dyn std::error::Error>> {
let is_debug = std::env::var("TAURI_ENV_DEBUG").unwrap_or("false".to_string()) == "true";
- if cfg!(debug_assertions) || is_debug {
- info!("skipping analytics in development mode");
- return Ok(Arc::new(AnalyticsManager::new(
- posthog_api_key,
- unique_id,
- email,
- interval_hours,
- local_api_base_url,
- screenpipe_dir_path,
- )));
- }
+
+ // Skip analytics in debug mode or when debug assertions are enabled
+ let should_enable_analytics = analytics_enabled && !is_debug && !cfg!(debug_assertions);
let analytics_manager = Arc::new(AnalyticsManager::new(
posthog_api_key,
@@ -228,6 +223,7 @@ pub fn start_analytics(
interval_hours,
local_api_base_url,
screenpipe_dir_path,
+ should_enable_analytics,
));
// Send initial event at boot
diff --git a/screenpipe-app-tauri/src-tauri/src/disk_usage.rs b/screenpipe-app-tauri/src-tauri/src/disk_usage.rs
index 2f8d9bc4e..6cdddcf6d 100644
--- a/screenpipe-app-tauri/src-tauri/src/disk_usage.rs
+++ b/screenpipe-app-tauri/src-tauri/src/disk_usage.rs
@@ -70,11 +70,27 @@ pub fn readable(size: u64) -> String {
}
pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, String> {
+ // Create base directories if they don't exist
+ fs::create_dir_all(screenpipe_dir).map_err(|e| e.to_string())?;
+
+ let pipes_dir = screenpipe_dir.join("pipes");
+ let data_dir = screenpipe_dir.join("data");
+
+ // Create required subdirectories
+ fs::create_dir_all(&pipes_dir).map_err(|e| e.to_string())?;
+ fs::create_dir_all(&data_dir).map_err(|e| e.to_string())?;
+
let cache_dir = match get_cache_dir()? {
Some(dir) => dir,
None => return Err("Cache directory not found".to_string()),
};
- let cache_file = cache_dir.join("screenpipe").join("disk_usage.json");
+ fs::create_dir_all(&cache_dir).map_err(|e| e.to_string())?;
+
+ // Create screenpipe subdirectory in cache
+ let screenpipe_cache_dir = cache_dir.join("screenpipe");
+ fs::create_dir_all(&screenpipe_cache_dir).map_err(|e| e.to_string())?;
+
+ let cache_file = screenpipe_cache_dir.join("disk_usage.json");
// Check if cache exists and is recent
if let Ok(content) = fs::read_to_string(&cache_file) {
@@ -96,13 +112,6 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, S
let mut total_video_size = 0;
let mut total_audio_size = 0;
- let pipes_dir = screenpipe_dir.join("pipes");
- let data_dir = screenpipe_dir.join("data");
- let cache_dir = match get_cache_dir()? {
- Some(dir) => dir,
- None => return Err("Cache directory not found".to_string()),
- };
-
for entry in fs::read_dir(&pipes_dir).map_err(|e| e.to_string())? {
let entry = entry.map_err(|e| e.to_string())?;
let path = entry.path();
@@ -118,7 +127,7 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, S
let total_data_size = directory_size(screenpipe_dir).map_err(|e| e.to_string())?;
let total_media_size = directory_size(&data_dir).map_err(|e| e.to_string())?;
let total_pipes_size = directory_size(&pipes_dir).map_err(|e| e.to_string())?;
- let total_cache_size = directory_size(&cache_dir).map_err(|e| e.to_string())?;
+ let total_cache_size = directory_size(&screenpipe_cache_dir).map_err(|e| e.to_string())?;
for entry in fs::read_dir(&data_dir).map_err(|e| e.to_string())? {
let entry = entry.map_err(|e| e.to_string())?;
@@ -166,11 +175,10 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, S
usage: disk_usage.clone(),
};
- if let Err(e) = fs::create_dir_all(&cache_dir) {
- info!("Failed to create cache directory: {}", e);
- } else if let Err(e) = fs::write(&cache_file, serde_json::to_string_pretty(&cached).unwrap()) {
+ if let Err(e) = fs::write(&cache_file, serde_json::to_string_pretty(&cached).unwrap()) {
info!("Failed to write cache file: {}", e);
}
+
Ok(Some(disk_usage))
}
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 1ef54a34a..efa8f7fdc 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -760,6 +760,7 @@ async fn main() {
interval_hours,
"http://localhost:3030".to_string(),
base_dir.clone(),
+ is_analytics_enabled,
) {
Ok(analytics_manager) => {
app.manage(analytics_manager);
diff --git a/screenpipe-core/src/pipes.rs b/screenpipe-core/src/pipes.rs
index 5360173de..2f50a71e8 100644
--- a/screenpipe-core/src/pipes.rs
+++ b/screenpipe-core/src/pipes.rs
@@ -87,16 +87,35 @@ mod pipes {
$parentPid = {parent_pid}
$childPid = {child_pid}
+function Get-ChildProcesses($ProcessId) {{
+ Get-WmiObject Win32_Process | Where-Object {{ $_.ParentProcessId -eq $ProcessId }} | ForEach-Object {{
+ $_.ProcessId
+ Get-ChildProcesses $_.ProcessId
+ }}
+}}
+
while ($true) {{
try {{
$parent = Get-Process -Id $parentPid -ErrorAction Stop
Start-Sleep -Seconds 1
}} catch {{
- try {{
- Stop-Process -Id $childPid -Force
- }} catch {{
- # Process might already be gone
+ Write-Host "Parent process ($parentPid) not found, terminating child processes"
+
+ # Get all child processes recursively
+ $children = Get-ChildProcesses $childPid
+
+ # Add the main process to the list
+ $allProcesses = @($childPid) + $children
+
+ foreach ($pid in $allProcesses) {{
+ try {{
+ Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
+ Write-Host "Stopped process: $pid"
+ }} catch {{
+ Write-Host "Process $pid already terminated"
+ }}
}}
+
exit
}}
}}
@@ -127,16 +146,16 @@ cleanup() {{
all_children=$(find_all_children $child_pid)
echo "[$(date)] Found child processes: $all_children"
- # Try process group first
+ # Try to kill by process group first
child_pgid=$(ps -o pgid= -p $child_pid 2>/dev/null | tr -d ' ')
if [ ! -z "$child_pgid" ]; then
echo "[$(date)] Killing process group $child_pgid"
- kill -TERM -$child_pgid 2>/dev/null || true
+ pkill -TERM -g $child_pgid 2>/dev/null || true
sleep 1
- kill -KILL -$child_pgid 2>/dev/null || true
+ pkill -KILL -g $child_pgid 2>/dev/null || true
fi
- # Kill all children we found
+ # Kill all children individually if they still exist
if [ ! -z "$all_children" ]; then
echo "[$(date)] Killing all child processes: $all_children"
kill -TERM $all_children 2>/dev/null || true
@@ -144,15 +163,19 @@ cleanup() {{
kill -KILL $all_children 2>/dev/null || true
fi
- # Kill the main process
+ # Kill the main process if it still exists
echo "[$(date)] Killing main process $child_pid"
kill -TERM $child_pid 2>/dev/null || true
sleep 1
kill -KILL $child_pid 2>/dev/null || true
- # Verify all processes are gone
+ # Final verification
sleep 1
- ps aux | grep -E "($child_pid|$all_children)" | grep -v grep
+ remaining=$(ps -o pid= -g $child_pgid 2>/dev/null || true)
+ if [ ! -z "$remaining" ]; then
+ echo "[$(date)] WARNING: Some processes might still be running: $remaining"
+ pkill -KILL -g $child_pgid 2>/dev/null || true
+ fi
exit 0
}}