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

feat: impl auto destruction + #304 and other ui things

Louis Beaumont2160e3c7894d
diff --git a/screenpipe-app-tauri/app/page.tsx b/screenpipe-app-tauri/app/page.tsx
index 5bd7af0e1..41fa81175 100644
--- a/screenpipe-app-tauri/app/page.tsx
+++ b/screenpipe-app-tauri/app/page.tsx
@@ -61,7 +61,7 @@ export default function Home() {
))}
</div>
</div>
- ) : settings.useOllama || settings.openaiApiKey ? (
+ ) : settings.aiUrl ? (
<>
<h1 className="text-2xl font-bold mb-8 text-center mb-12">
where pixels become magic
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index e894e93e0..d02ad0262 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.2.44"
+version = "0.2.45"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 49e887a7b..a978308b2 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -324,30 +324,7 @@ async fn main() {
}
tauri::RunEvent::ExitRequested { .. } => {
debug!("ExitRequested event");
- let app_handle_clone = app_handle.clone();
- let app_handle_clone2 = app_handle.clone();
- let stores = app_handle.state::<StoreCollection<Wry>>();
- let path = app_handle
- .path()
- .local_data_dir()
- .unwrap()
- .join("store.bin");
- let use_dev_mode = with_store(app_handle.clone(), stores, path, |store| {
- Ok(store
- .get("devMode")
- .unwrap_or(&Value::Bool(false))
- .as_bool()
- .unwrap_or(false))
- })
- .unwrap_or(false);
- if !use_dev_mode {
- tauri::async_runtime::spawn(async move {
- let state = app_handle_clone.state::<SidecarState>();
- if let Err(e) = kill_all_sreenpipes(state, app_handle_clone2).await {
- error!("Failed to kill screenpipe processes: {}", e);
- }
- });
- }
+
// Add this to shut down the server
if let Some(server_shutdown_tx) = app_handle.try_state::<mpsc::Sender<()>>() {
let _ = server_shutdown_tx.send(());
diff --git a/screenpipe-app-tauri/src-tauri/src/sidecar.rs b/screenpipe-app-tauri/src-tauri/src/sidecar.rs
index aeef74581..75f3b63fa 100644
--- a/screenpipe-app-tauri/src-tauri/src/sidecar.rs
+++ b/screenpipe-app-tauri/src-tauri/src/sidecar.rs
@@ -177,14 +177,22 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
Ok(store
.get("fps")
.and_then(|v| v.as_f64())
- .unwrap_or(0.5))
+ .unwrap_or(0.2))
+ })
+ .map_err(|e| e.to_string())?;
+
+ let dev_mode = with_store(app.clone(), stores.clone(), path.clone(), |store| {
+ Ok(store
+ .get("devMode")
+ .and_then(|v| v.as_bool())
+ .unwrap_or(false))
})
.map_err(|e| e.to_string())?;
let port_str = port.to_string();
let mut args = vec!["--port", port_str.as_str()];
let fps_str = fps.to_string();
- if fps != 0.5 {
+ if fps != 0.2 {
args.push("--fps");
args.push(fps_str.as_str());
}
@@ -253,6 +261,13 @@ fn spawn_sidecar(app: &tauri::AppHandle) -> Result<CommandChild, String> {
args.push(window);
}
}
+ let current_pid = std::process::id();
+ let current_pid_str = current_pid.to_string();
+ // Set auto-destruct PID if not in dev mode
+ if !dev_mode {
+ args.push("--auto-destruct-pid");
+ args.push(current_pid_str.as_str());
+ }
// args.push("--debug");
@@ -333,7 +348,6 @@ impl SidecarManager {
debug!("last_restart: {:?}", self.last_restart);
// kill previous task if any
-
if let Some(task) = self.restart_task.take() {
task.abort();
}
@@ -363,6 +377,8 @@ impl SidecarManager {
}
}));
+
+
Ok(())
}
diff --git a/screenpipe-server/src/auto_destruct.rs b/screenpipe-server/src/auto_destruct.rs
new file mode 100644
index 000000000..85fd15dfe
--- /dev/null
+++ b/screenpipe-server/src/auto_destruct.rs
@@ -0,0 +1,19 @@
+use std::process::Command;
+use std::time::Duration;
+use tokio::time::sleep;
+
+pub async fn watch_pid(pid: u32) -> bool {
+ loop {
+ let output = Command::new("ps")
+ .arg("-p")
+ .arg(pid.to_string())
+ .output()
+ .expect("failed to execute ps command");
+
+ if !output.status.success() {
+ return true;
+ }
+
+ sleep(Duration::from_secs(1)).await;
+ }
+}
\ No newline at end of file
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 232b2e0ca..8d4526977 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -16,8 +16,7 @@ use screenpipe_audio::{
};
use screenpipe_core::find_ffmpeg_path;
use screenpipe_server::{
- cli::{Cli, CliAudioTranscriptionEngine, CliOcrEngine, Command, PipeCommand},
- start_continuous_recording, DatabaseManager, PipeManager, ResourceMonitor, Server,
+ cli::{Cli, CliAudioTranscriptionEngine, CliOcrEngine, Command, PipeCommand}, start_continuous_recording, watch_pid, DatabaseManager, PipeManager, ResourceMonitor, Server
};
use screenpipe_vision::monitor::list_monitors;
use serde_json::{json, Value};
@@ -28,6 +27,7 @@ use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;
use tracing_subscriber::{fmt, EnvFilter};
+
fn print_devices(devices: &[AudioDevice]) {
println!("available audio devices:");
for device in devices.iter() {
@@ -558,6 +558,18 @@ async fn main() -> anyhow::Result<()> {
};
pin_mut!(pipes_future);
+ // Add auto-destruct watcher
+ if let Some(pid) = cli.auto_destruct_pid {
+ info!("watching pid {} for auto-destruction", pid);
+ let shutdown_tx_clone = shutdown_tx.clone();
+ tokio::spawn(async move {
+ if watch_pid(pid).await {
+ info!("watched pid {} has stopped, initiating shutdown", pid);
+ let _ = shutdown_tx_clone.send(());
+ }
+ });
+ }
+
let ctrl_c_future = signal::ctrl_c();
pin_mut!(ctrl_c_future);
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index ed324a2f2..ab0a8cb5e 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -82,7 +82,7 @@ pub struct Cli {
/// Optimise based on your needs.
/// Your screen rarely change more than 1 times within a second, right?
#[cfg_attr(not(target_os = "macos"), arg(short, long, default_value_t = 1.0))]
- #[cfg_attr(target_os = "macos", arg(short, long, default_value_t = 0.5))]
+ #[cfg_attr(target_os = "macos", arg(short, long, default_value_t = 0.2))]
pub fps: f64, // ! not crazy about this (unconsistent behaviour across platforms) see https://github.com/mediar-ai/screenpipe/issues/173
/// Audio chunk duration in seconds
@@ -187,6 +187,10 @@ pub struct Cli {
#[arg(long = "deepgram-api-key")]
pub deepgram_api_key: Option<String>,
+ /// PID to watch for auto-destruction. If provided, screenpipe will stop when this PID is no longer running.
+ #[arg(long)]
+ pub auto_destruct_pid: Option<u32>,
+
#[command(subcommand)]
pub command: Option<Command>,
}
diff --git a/screenpipe-server/src/lib.rs b/screenpipe-server/src/lib.rs
index 4553c4889..afcd87a61 100644
--- a/screenpipe-server/src/lib.rs
+++ b/screenpipe-server/src/lib.rs
@@ -11,6 +11,8 @@ mod server;
mod video;
mod video_db;
mod video_utils;
+mod auto_destruct;
+pub use auto_destruct::watch_pid;
pub use cli::Cli;
pub use core::start_continuous_recording;
pub use db::{ContentSource, ContentType, DatabaseManager, SearchResult};