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
Bump app to v2.0.181
Louis Beaumonte776a493e33c
diff --git a/Cargo.lock b/Cargo.lockindex 6ad32d7e9..82ede6355 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -24,7 +24,7 @@ version = "0.2.0"source = "git+https://github.com/eiz/accessibility.git?branch=master#63a4a9c4ecdc143bed1d65b989aa18bbc5fd8129"dependencies = ["accessibility-sys",- "cocoa",+ "cocoa 0.26.0","core-foundation 0.10.0","objc","thiserror 1.0.69",@@ -35,7 +35,7 @@ name = "accessibility-sys"version = "0.2.0"source = "git+https://github.com/eiz/accessibility.git?branch=master#63a4a9c4ecdc143bed1d65b989aa18bbc5fd8129"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7",][[package]]@@ -1288,6 +1288,21 @@ dependencies = ["cc",]+[[package]]+name = "cocoa"+version = "0.22.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7"+dependencies = [+ "bitflags 1.3.2",+ "block",+ "core-foundation 0.9.4",+ "core-graphics 0.21.0",+ "foreign-types 0.3.2",+ "libc",+ "objc",+]+[[package]]name = "cocoa"version = "0.26.0"@@ -1298,7 +1313,7 @@ dependencies = ["block","cocoa-foundation","core-foundation 0.10.0",- "core-graphics",+ "core-graphics 0.24.0","foreign-types 0.5.0","libc","objc",@@ -1447,13 +1462,23 @@ dependencies = ["futures",]+[[package]]+name = "core-foundation"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"+dependencies = [+ "core-foundation-sys 0.7.0",+ "libc",+]+[[package]]name = "core-foundation"version = "0.9.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc",]@@ -1463,16 +1488,46 @@ version = "0.10.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc",]+[[package]]+name = "core-foundation-sys"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"+[[package]]name = "core-foundation-sys"version = "0.8.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"+[[package]]+name = "core-graphics"+version = "0.19.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923"+dependencies = [+ "bitflags 1.3.2",+ "core-foundation 0.7.0",+ "foreign-types 0.3.2",+ "libc",+]++[[package]]+name = "core-graphics"+version = "0.21.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978"+dependencies = [+ "bitflags 1.3.2",+ "core-foundation 0.9.4",+ "foreign-types 0.3.2",+ "libc",+]+[[package]]name = "core-graphics"version = "0.24.0"@@ -1515,7 +1570,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "321077172d79c662f64f5071a03120748d5bb652f5231570141be24cfcd2bace"dependencies = ["bitflags 1.3.2",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","coreaudio-sys",]@@ -1535,7 +1590,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "873dab07c8f743075e57f524c583985fbaf745602acbe916a01539364369a779"dependencies = ["alsa",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","coreaudio-rs","dasp_sample","jni",@@ -1558,7 +1613,7 @@ source = "git+https://github.com/louis030195/cpal.git?branch=main#c3eaee9cb793c9dependencies = ["alsa","cidre",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","coreaudio-rs","dasp_sample","jni",@@ -3381,7 +3436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"dependencies = ["android_system_properties",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","iana-time-zone-haiku","js-sys","wasm-bindgen",@@ -6053,6 +6108,22 @@ dependencies = ["crossbeam-utils",]+[[package]]+name = "rdev"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "00552ca2dc2f93b84cd7b5581de49549411e4e41d89e1c691bcb93dc4be360c3"+dependencies = [+ "cocoa 0.22.0",+ "core-foundation 0.7.0",+ "core-foundation-sys 0.7.0",+ "core-graphics 0.19.2",+ "lazy_static",+ "libc",+ "winapi",+ "x11",+]+[[package]]name = "realfft"version = "3.4.0"@@ -6563,7 +6634,7 @@ source = "git+https://github.com/louis030195/sck-rs#f3667badac256c097ee616e452c9dependencies = ["cidre","core-foundation 0.10.0",- "core-graphics",+ "core-graphics 0.24.0","image","once_cell","thiserror 1.0.69",@@ -6653,7 +6724,7 @@ dependencies = ["chrono","clap","core-foundation 0.10.0",- "core-graphics",+ "core-graphics 0.24.0","cron","dirs","ffmpeg-sidecar",@@ -6830,6 +6901,7 @@ dependencies = ["libc","memory-stats","once_cell",+ "rdev","reqwest 0.12.12","rusty-tesseract","sck-rs",@@ -6875,7 +6947,7 @@ checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"dependencies = ["bitflags 2.9.0","core-foundation 0.9.4",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc","security-framework-sys",]@@ -6886,7 +6958,7 @@ version = "2.14.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc",]@@ -7947,7 +8019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666"dependencies = ["cfg-if",- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc","ntapi","once_cell",@@ -7983,7 +8055,7 @@ version = "0.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc",]@@ -7993,7 +8065,7 @@ version = "0.6.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"dependencies = [- "core-foundation-sys",+ "core-foundation-sys 0.8.7","libc",]@@ -9880,6 +9952,16 @@ version = "0.5.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"+[[package]]+name = "x11"+version = "2.21.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e"+dependencies = [+ "libc",+ "pkg-config",+]+[[package]]name = "xattr"version = "1.4.0"diff --git a/screenpipe-app-tauri/components/settings/recording-settings.tsx b/screenpipe-app-tauri/components/settings/recording-settings.tsxindex 50e054b1e..7cb58b3ee 100644--- a/screenpipe-app-tauri/components/settings/recording-settings.tsx+++ b/screenpipe-app-tauri/components/settings/recording-settings.tsx@@ -900,6 +900,39 @@ export function RecordingSettings() {)}</div>+ {/* Adaptive FPS Toggle */}+ <div className="flex items-center justify-between">+ <div className="space-y-1">+ <Label htmlFor="adaptiveFps" className="flex items-center space-x-2">+ <span>Adaptive FPS</span>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger>+ <HelpCircle className="h-4 w-4 cursor-default" />+ </TooltipTrigger>+ <TooltipContent side="right">+ <p>+ Automatically increase capture rate during mouse/keyboard activity+ (up to 5 FPS) and decrease during idle periods. Helps capture fast+ workflows without missing data.+ </p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </Label>+ <p className="text-sm text-muted-foreground">+ Boost FPS during activity, reduce when idle+ </p>+ </div>+ <Switch+ id="adaptiveFps"+ checked={settings.adaptiveFps}+ onCheckedChange={(checked) =>+ handleSettingsChange({ adaptiveFps: checked }, true)+ }+ />+ </div>+{/* Enhanced Audio Chunk Duration Section */}<div className="flex flex-col space-y-2"><Labeldiff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex f575f5f52..bbdb43926 100644--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -219,6 +219,7 @@ let DEFAULT_SETTINGS: Settings = {realtimeAudioTranscriptionEngine: "deepgram",disableVision: false,useAllMonitors: true,+ adaptiveFps: false,enableRealtimeVision: true,showShortcutOverlay: true,chatHistory: {diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex f374820ae..7163884df 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 = "2.0.180"+version = "2.0.181"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rsindex 5e0cfce9d..c9aa4f39d 100644--- a/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -594,7 +594,7 @@ pub fn register_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), Str// Default fallback if empty or parse fails#[cfg(target_os = "windows")]- let default_search = "Control+Alt+K";+ let default_search = "Alt+K";#[cfg(not(target_os = "windows"))]let default_search = "Control+Super+K";@@ -649,7 +649,7 @@ pub fn unregister_window_shortcuts(app_handle: tauri::AppHandle) -> Result<(), S// Default fallback if empty#[cfg(target_os = "windows")]- let default_search = "Control+Alt+K";+ let default_search = "Alt+K";#[cfg(not(target_os = "windows"))]let default_search = "Control+Super+K";diff --git a/screenpipe-app-tauri/src-tauri/src/sidecar.rs b/screenpipe-app-tauri/src-tauri/src/sidecar.rsindex abcc86d43..ff5125a43 100644--- a/screenpipe-app-tauri/src-tauri/src/sidecar.rs+++ b/screenpipe-app-tauri/src-tauri/src/sidecar.rs@@ -503,6 +503,12 @@ async fn spawn_sidecar(app: &tauri::AppHandle, override_args: Option<Vec<String>args.push("--disable-vision");}+ let adaptive_fps = store.adaptive_fps;++ if adaptive_fps {+ args.push("--adaptive-fps");+ }+// args.push("--debug");let override_args_as_vec = override_args.unwrap_or_default();diff --git a/screenpipe-app-tauri/src-tauri/src/store.rs b/screenpipe-app-tauri/src-tauri/src/store.rsindex 66f443249..51ea3e71c 100644--- a/screenpipe-app-tauri/src-tauri/src/store.rs+++ b/screenpipe-app-tauri/src-tauri/src/store.rs@@ -190,6 +190,8 @@ pub struct SettingsStore {pub disable_vision: bool,#[serde(rename = "useAllMonitors")]pub use_all_monitors: bool,+ #[serde(rename = "adaptiveFps", default)]+ pub adaptive_fps: bool,#[serde(rename = "enableRealtimeVision")]pub enable_realtime_vision: bool,#[serde(rename = "showShortcutOverlay", default = "default_true")]@@ -465,7 +467,7 @@ impl Default for SettingsStore {#[cfg(not(target_os = "windows"))]show_chat_shortcut: "Control+Super+L".to_string(),#[cfg(target_os = "windows")]- search_shortcut: "Control+Alt+K".to_string(),+ search_shortcut: "Alt+K".to_string(),#[cfg(not(target_os = "windows"))]search_shortcut: "Control+Super+K".to_string(),enable_realtime_audio_transcription: false,diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.tomlindex cf017c65e..da782a237 100644--- a/screenpipe-server/Cargo.toml+++ b/screenpipe-server/Cargo.toml@@ -135,6 +135,7 @@ mkl = ["candle/mkl", "candle-nn/mkl", "candle-transformers/mkl"]llm = []experimental = []debug-console = ["console-subscriber"]+adaptive-fps = ["screenpipe-vision/adaptive-fps"][[bin]]name = "screenpipe"diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rsindex 485759ef5..d71485fa5 100644--- a/screenpipe-server/src/bin/screenpipe-server.rs+++ b/screenpipe-server/src/bin/screenpipe-server.rs@@ -785,6 +785,7 @@ async fn main() -> anyhow::Result<()> {languages: languages_clone.clone(),capture_unfocused_windows: cli.capture_unfocused_windows,realtime_vision: cli.enable_realtime_audio_transcription,+ adaptive_fps: cli.adaptive_fps,};Some(Arc::new(VisionManager::new(config,@@ -846,6 +847,7 @@ async fn main() -> anyhow::Result<()> {languages_clone.clone(),cli.capture_unfocused_windows,cli.enable_realtime_audio_transcription,+ cli.adaptive_fps,);let result = tokio::select! {diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rsindex 803798dc2..d7991f2da 100644--- a/screenpipe-server/src/cli.rs+++ b/screenpipe-server/src/cli.rs@@ -160,6 +160,13 @@ pub struct Cli {#[cfg_attr(target_os = "macos", arg(short, long, default_value_t = 0.5))]pub fps: f64, // ! not crazy about this (inconsistent behaviour across platforms) see https://github.com/mediar-ai/screenpipe/issues/173+ /// Enable adaptive FPS based on input activity.+ /// When enabled, capture rate increases during mouse/keyboard activity (up to 5 FPS)+ /// and decreases during idle periods (down to base FPS).+ /// Requires the 'adaptive-fps' feature to be enabled.+ #[arg(long, default_value_t = false)]+ pub adaptive_fps: bool,+/// Audio chunk duration in seconds#[arg(short = 'd', long, default_value_t = 30)]pub audio_chunk_duration: u64,diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rsindex af10fea5e..c62ad6ece 100644--- a/screenpipe-server/src/core.rs+++ b/screenpipe-server/src/core.rs@@ -29,6 +29,7 @@ pub async fn start_continuous_recording(languages: Vec<Language>,capture_unfocused_windows: bool,realtime_vision: bool,+ adaptive_fps: bool,) -> Result<()> {debug!("Starting video recording for monitors {:?}", monitor_ids);let video_tasks = if !vision_disabled {@@ -63,6 +64,7 @@ pub async fn start_continuous_recording(languages.clone(),capture_unfocused_windows,realtime_vision,+ adaptive_fps,).await{@@ -128,6 +130,7 @@ pub async fn record_video(languages: Vec<Language>,capture_unfocused_windows: bool,realtime_vision: bool,+ adaptive_fps: bool,) -> Result<()> {debug!("record_video: Starting for monitor {}", monitor_id);let device_name = Arc::new(format!("monitor_{}", monitor_id));@@ -175,6 +178,7 @@ pub async fn record_video(ignored_urls,languages,capture_unfocused_windows,+ adaptive_fps,);info!(diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rsindex b8019f822..3bdb3a2bd 100644--- a/screenpipe-server/src/video.rs+++ b/screenpipe-server/src/video.rs@@ -127,6 +127,7 @@ impl VideoCapture {ignored_urls: &[String],languages: Vec<Language>,capture_unfocused_windows: bool,+ adaptive_fps: bool,) -> Self {let fps = if fps.is_finite() && fps > 0.0 {fps@@ -161,6 +162,7 @@ impl VideoCapture {let capture_result_sender = result_sender.clone();let capture_interval = interval;let capture_unfocused = capture_unfocused_windows;+ let capture_adaptive_fps = adaptive_fps;// Store task handles for health monitoringlet capture_thread = tokio::spawn(async move {@@ -190,6 +192,7 @@ impl VideoCapture {capture_window_filters.clone(),capture_languages.clone(),capture_unfocused,+ capture_adaptive_fps,).await{diff --git a/screenpipe-server/src/vision_manager/manager.rs b/screenpipe-server/src/vision_manager/manager.rsindex 7343737e9..51d973f15 100644--- a/screenpipe-server/src/vision_manager/manager.rs+++ b/screenpipe-server/src/vision_manager/manager.rs@@ -29,6 +29,7 @@ pub struct VisionManagerConfig {pub languages: Vec<Language>,pub capture_unfocused_windows: bool,pub realtime_vision: bool,+ pub adaptive_fps: bool,}/// Status of the VisionManager@@ -163,6 +164,7 @@ impl VisionManager {let languages = self.config.languages.clone();let capture_unfocused_windows = self.config.capture_unfocused_windows;let realtime_vision = self.config.realtime_vision;+ let adaptive_fps = self.config.adaptive_fps;// Spawn the recording task using the existing record_video functionlet handle = self.vision_handle.spawn(async move {@@ -181,6 +183,7 @@ impl VisionManager {languages.clone(),capture_unfocused_windows,realtime_vision,+ adaptive_fps,).await{diff --git a/screenpipe-vision/Cargo.toml b/screenpipe-vision/Cargo.tomlindex 21e73ab0f..45634368c 100644--- a/screenpipe-vision/Cargo.toml+++ b/screenpipe-vision/Cargo.toml@@ -10,7 +10,13 @@ edition = { workspace = true }# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html+[features]+default = []+adaptive-fps = ["rdev"]+[dependencies]+# Input activity monitoring for adaptive FPS (optional)+rdev = { version = "0.5", optional = true }serde_json = "1.0"chrono = { version = "0.4.31", features = ["serde"] }diff --git a/screenpipe-vision/src/activity.rs b/screenpipe-vision/src/activity.rsnew file mode 100644index 000000000..cdbc37700--- /dev/null+++ b/screenpipe-vision/src/activity.rs@@ -0,0 +1,141 @@+//! Activity monitoring for adaptive FPS capture.+//!+//! This module provides input activity detection using rdev to dynamically+//! adjust capture rates based on user activity (mouse/keyboard events).++use std::sync::atomic::{AtomicU64, Ordering};+use std::sync::Arc;+use std::time::Duration;+use tracing::{debug, error, info};++/// Tracks input activity to determine optimal capture rate.+///+/// Spawns a background thread that listens for mouse/keyboard events+/// and updates an atomic timestamp. The capture loop can query this+/// to determine if the user is active and adjust FPS accordingly.+pub struct ActivityMonitor {+ last_activity: Arc<AtomicU64>,+ base_interval: Duration,+}++impl ActivityMonitor {+ /// Create a new ActivityMonitor and start listening for input events.+ ///+ /// # Arguments+ /// * `base_interval` - The default capture interval when user is idle+ pub fn new(base_interval: Duration) -> Self {+ let last_activity = Arc::new(AtomicU64::new(current_time_ms()));+ let activity_clone = last_activity.clone();++ // Spawn listener thread (rdev::listen blocks, so needs its own thread)+ std::thread::Builder::new()+ .name("activity-monitor".to_string())+ .spawn(move || {+ info!("Starting input activity monitor");++ let callback = move |event: rdev::Event| {+ match event.event_type {+ // Key events - always update+ rdev::EventType::KeyPress(_) | rdev::EventType::KeyRelease(_) => {+ activity_clone.store(current_time_ms(), Ordering::Relaxed);+ }+ // Mouse button events - always update+ rdev::EventType::ButtonPress(_) | rdev::EventType::ButtonRelease(_) => {+ activity_clone.store(current_time_ms(), Ordering::Relaxed);+ }+ // Scroll events - always update+ rdev::EventType::Wheel { .. } => {+ activity_clone.store(current_time_ms(), Ordering::Relaxed);+ }+ // Mouse move - throttle to reduce overhead+ rdev::EventType::MouseMove { .. } => {+ let now = current_time_ms();+ let last = activity_clone.load(Ordering::Relaxed);+ // Only update if more than 100ms since last activity+ if now.saturating_sub(last) > 100 {+ activity_clone.store(now, Ordering::Relaxed);+ }+ }+ }+ };++ if let Err(e) = rdev::listen(callback) {+ error!("Input activity listener error: {:?}", e);+ }+ })+ .expect("Failed to spawn activity monitor thread");++ Self {+ last_activity,+ base_interval,+ }+ }++ /// Returns the optimal capture interval based on recent activity.+ ///+ /// Activity tiers:+ /// - < 500ms since activity: 200ms interval (5 FPS) - active+ /// - < 2000ms: 500ms interval (2 FPS) - cooling down+ /// - < 5000ms: 1000ms interval (1 FPS) - idle+ /// - > 5000ms: base_interval - deep idle+ pub fn get_interval(&self) -> Duration {+ let now = current_time_ms();+ let last = self.last_activity.load(Ordering::Relaxed);+ let idle_ms = now.saturating_sub(last);++ let interval = if idle_ms < 500 {+ // Active - capture at 5 FPS+ Duration::from_millis(200)+ } else if idle_ms < 2000 {+ // Cooling down - 2 FPS+ Duration::from_millis(500)+ } else if idle_ms < 5000 {+ // Idle - 1 FPS+ Duration::from_millis(1000)+ } else {+ // Deep idle - use base interval+ self.base_interval+ };++ debug!(+ "Activity monitor: idle_ms={}, interval={}ms",+ idle_ms,+ interval.as_millis()+ );++ interval+ }++ /// Returns milliseconds since last detected activity.+ pub fn idle_time_ms(&self) -> u64 {+ let now = current_time_ms();+ let last = self.last_activity.load(Ordering::Relaxed);+ now.saturating_sub(last)+ }++ /// Returns true if user was active in the last N milliseconds.+ pub fn is_active(&self, threshold_ms: u64) -> bool {+ self.idle_time_ms() < threshold_ms+ }+}++/// Get current time in milliseconds since UNIX epoch.+fn current_time_ms() -> u64 {+ std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .unwrap_or_default()+ .as_millis() as u64+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_current_time_ms() {+ let t1 = current_time_ms();+ std::thread::sleep(Duration::from_millis(10));+ let t2 = current_time_ms();+ assert!(t2 > t1);+ }+}diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rsindex 60c0d02d7..4f131c7ff 100644--- a/screenpipe-vision/src/core.rs+++ b/screenpipe-vision/src/core.rs@@ -152,12 +152,26 @@ pub async fn continuous_capture(window_filters: Arc<WindowFilters>,languages: Vec<Language>,capture_unfocused_windows: bool,+ adaptive_fps: bool,) -> Result<(), ContinuousCaptureError> {let mut frame_counter: u64 = 0;let mut previous_image: Option<DynamicImage> = None;let mut max_average: Option<MaxAverageFrame> = None;let mut max_avg_value = 0.0;+ // Initialize activity monitor for adaptive FPS if enabled+ #[cfg(feature = "adaptive-fps")]+ let activity_monitor = if adaptive_fps {+ Some(crate::activity::ActivityMonitor::new(interval))+ } else {+ None+ };++ #[cfg(feature = "adaptive-fps")]+ if adaptive_fps {+ debug!("Adaptive FPS enabled - will adjust capture rate based on input activity");+ }+// Initialize OCR cache for skipping unchanged windows// Cache entries expire after 5 minutes, max 100 windows cachedlet ocr_cache = Arc::new(Mutex::new(WindowOcrCache::new(@@ -178,6 +192,10 @@ pub async fn continuous_capture(}};+ // Suppress unused variable warning when feature is disabled+ #[cfg(not(feature = "adaptive-fps"))]+ let _ = adaptive_fps;+loop {// 3. Capture screenshot and wall-clock time atomicallylet captured_at = Utc::now();@@ -210,7 +228,15 @@ pub async fn continuous_capture(if should_skip {frame_counter += 1;- tokio::time::sleep(interval).await;+ // Use adaptive interval if enabled, otherwise use base interval+ #[cfg(feature = "adaptive-fps")]+ let sleep_interval = activity_monitor+ .as_ref()+ .map(|m| m.get_interval())+ .unwrap_or(interval);+ #[cfg(not(feature = "adaptive-fps"))]+ let sleep_interval = interval;+ tokio::time::sleep(sleep_interval).await;continue;}@@ -233,7 +259,15 @@ pub async fn continuous_capture(}frame_counter += 1;- tokio::time::sleep(interval).await;+ // Use adaptive interval if enabled, otherwise use base interval+ #[cfg(feature = "adaptive-fps")]+ let sleep_interval = activity_monitor+ .as_ref()+ .map(|m| m.get_interval())+ .unwrap_or(interval);+ #[cfg(not(feature = "adaptive-fps"))]+ let sleep_interval = interval;+ tokio::time::sleep(sleep_interval).await;}}diff --git a/screenpipe-vision/src/lib.rs b/screenpipe-vision/src/lib.rsindex 000e40e16..b683ce033 100644--- a/screenpipe-vision/src/lib.rs+++ b/screenpipe-vision/src/lib.rs@@ -1,3 +1,5 @@+#[cfg(feature = "adaptive-fps")]+pub mod activity;#[cfg(target_os = "macos")]pub mod apple;pub mod core;