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(sync): auto-download from other devices after each upload cycle

Louis Beaumont2f6b2af5ac9c
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index acdda9a06..11ee77f7b 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9007,7 +9007,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.329"
+version = "2.0.307"
dependencies = [
"anyhow",
"async-stream",
@@ -9042,7 +9042,6 @@ dependencies = [
"regex",
"reqwest 0.12.12",
"resvg",
- "screenpipe-accessibility",
"screenpipe-audio",
"screenpipe-core",
"screenpipe-db",
@@ -9088,19 +9087,9 @@ dependencies = [
"xdg 2.5.2",
]
-[[package]]
-name = "screenpipe-apple-intelligence"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "serde",
- "serde_json",
- "tracing",
-]
-
[[package]]
name = "screenpipe-audio"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"anyhow",
"bytemuck",
@@ -9148,7 +9137,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -9199,7 +9188,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"anyhow",
"chrono",
@@ -9223,7 +9212,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"anyhow",
"chrono",
@@ -9239,7 +9228,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"anyhow",
"image 0.25.9",
@@ -9254,7 +9243,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"anyhow",
"async-trait",
@@ -9291,7 +9280,6 @@ dependencies = [
"reqwest 0.12.12",
"rust-stemmers",
"screenpipe-accessibility",
- "screenpipe-apple-intelligence",
"screenpipe-audio",
"screenpipe-core",
"screenpipe-db",
@@ -9306,7 +9294,6 @@ dependencies = [
"tempfile",
"tokenizers",
"tokio",
- "tokio-stream",
"tokio-util",
"tower 0.5.3",
"tower-http 0.5.2",
@@ -9320,7 +9307,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.123"
+version = "0.3.101"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -9340,7 +9327,6 @@ dependencies = [
"reqwest 0.12.12",
"rusty-tesseract",
"sck-rs",
- "screenpipe-accessibility",
"screenpipe-core",
"screenpipe-db",
"screenpipe-integrations",
diff --git a/crates/screenpipe-server/src/sync_api.rs b/crates/screenpipe-server/src/sync_api.rs
index 85c3f49a8..b35aca6a5 100644
--- a/crates/screenpipe-server/src/sync_api.rs
+++ b/crates/screenpipe-server/src/sync_api.rs
@@ -170,6 +170,11 @@ pub async fn sync_init(
let is_syncing = runtime_state.is_syncing.clone();
let last_sync = runtime_state.last_sync.clone();
let last_error = runtime_state.last_error.clone();
+ let sync_manager_for_events = manager.clone();
+ let sync_provider_for_events = Arc::new(ScreenpipeSyncProvider::new(
+ state.db.clone(),
+ machine_id.clone(),
+ ));
tokio::spawn(async move {
use screenpipe_core::sync::SyncEvent;
@@ -184,9 +189,42 @@ pub async fn sync_init(
"sync cycle completed: {} blobs uploaded ({} bytes) in {:.2}s",
report.blobs_uploaded, report.bytes_uploaded, report.duration_secs
);
- *is_syncing.write().await = false;
*last_sync.write().await = Some(chrono::Utc::now().to_rfc3339());
*last_error.write().await = None;
+
+ // Auto-download from other devices after upload
+ let end = chrono::Utc::now();
+ let start = end - chrono::Duration::hours(24);
+ match sync_manager_for_events.download_by_time_range(
+ Some(start.to_rfc3339()),
+ Some(end.to_rfc3339()),
+ None,
+ Some(100),
+ ).await {
+ Ok(blobs) if !blobs.is_empty() => {
+ info!("downloaded {} blobs from other devices", blobs.len());
+ let mut imported = 0;
+ for blob in blobs {
+ let chunk: Result<crate::sync_provider::SyncChunk, _> = serde_json::from_slice(&blob.data);
+ match chunk {
+ Ok(chunk) => {
+ match sync_provider_for_events.import_chunk(&chunk).await {
+ Ok(result) => {
+ imported += result.imported_frames + result.imported_ocr + result.imported_transcriptions + result.imported_accessibility + result.imported_ui_events;
+ }
+ Err(e) => error!("failed to import chunk: {}", e),
+ }
+ }
+ Err(e) => error!("failed to deserialize chunk: {}", e),
+ }
+ }
+ info!("imported {} records from other devices", imported);
+ }
+ Ok(_) => debug!("no new blobs from other devices"),
+ Err(e) => debug!("download from other devices failed: {}", e),
+ }
+
+ *is_syncing.write().await = false;
}
SyncEvent::Failed(err) => {
error!("sync cycle failed: {}", err);