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
fix fetching frames, disk_usage
shaik-zeeshan08cee8993842
diff --git a/openrewind/components/rewind/timeline.tsx b/openrewind/components/rewind/timeline.tsxindex b433b9474..0d56b6c6f 100644--- a/openrewind/components/rewind/timeline.tsx+++ b/openrewind/components/rewind/timeline.tsx@@ -102,16 +102,26 @@ export default function Timeline() {}, []);useEffect(() => {- const startTime = new Date(currentDate);- startTime.setHours(0, 0, 0, 0);+ let currentDateEffect = new Date(currentDate);+ const checkIfThereAreFrames = async () => {+ const checkFramesForDate = await hasFramesForDate(currentDateEffect);+ console.log("checkFramesForDate", currentDateEffect, checkFramesForDate);+ if (!checkFramesForDate) {+ setCurrentDate(subDays(currentDateEffect, 1));+ }- const endTime = new Date(currentDate);- if (endTime.getDate() === new Date().getDate()) {- endTime.setMinutes(endTime.getMinutes() + 5);- } else {- endTime.setHours(23, 59, 59, 999);+ const startTime = new Date(currentDateEffect);+ startTime.setHours(0, 0, 0, 0);++ const endTime = new Date(currentDateEffect);+ if (endTime.getDate() === new Date().getDate()) {+ endTime.setMinutes(endTime.getMinutes() - 5);+ } else {+ endTime.setHours(23, 59, 59, 999);+ }+ fetchTimeRange(startTime, endTime);}- fetchTimeRange(startTime, endTime);+ checkIfThereAreFrames();}, [currentDate]);useEffect(() => {diff --git a/openrewind/lib/actions/has-frames-date.ts b/openrewind/lib/actions/has-frames-date.tsindex 843614796..b191903e3 100644--- a/openrewind/lib/actions/has-frames-date.ts+++ b/openrewind/lib/actions/has-frames-date.ts@@ -1,11 +1,17 @@+import { isSameDay } from "date-fns";+export async function hasFramesForDate(date: Date) {try {// Set up start and end of the dayconst startOfDay = new Date(date);startOfDay.setHours(0, 0, 0, 0);- const endOfDay = new Date(date);- endOfDay.setHours(23, 59, 59, 999);+ let endOfDay = new Date(date);+ if (isSameDay(startOfDay, new Date())) {+ endOfDay.setMinutes(endOfDay.getMinutes() - 5);+ } else {+ endOfDay.setHours(23, 59, 59, 999);+ }const query = `SELECT COUNT(*) as frame_count@@ -31,6 +37,7 @@ export async function hasFramesForDate(date: Date) {}const result = await response.json();+ console.log("result", result);return result[0]?.frame_count > 0;} catch (e) {return {diff --git a/openrewind/src-tauri/src/commands.rs b/openrewind/src-tauri/src/commands.rsindex bc419edeb..1b2f4684c 100644--- a/openrewind/src-tauri/src/commands.rs+++ b/openrewind/src-tauri/src/commands.rs@@ -194,7 +194,7 @@ pub async fn get_disk_usage(app_handle: tauri::AppHandle,) -> Result<serde_json::Value, String> {let screenpipe_dir_path = get_data_dir(&app_handle)- .unwrap_or_else(|_| dirs::home_dir().unwrap().join(".openrewind"));+ .unwrap_or_else(|_| dirs::home_dir().unwrap().join(".screenpipe"));match crate::disk_usage::disk_usage(&screenpipe_dir_path).await {Ok(Some(disk_usage)) => match serde_json::to_value(&disk_usage) {Ok(json_value) => Ok(json_value),diff --git a/openrewind/src-tauri/src/disk_usage.rs b/openrewind/src-tauri/src/disk_usage.rsindex cd5cc72ef..2a2332cff 100644--- a/openrewind/src-tauri/src/disk_usage.rs+++ b/openrewind/src-tauri/src/disk_usage.rs@@ -54,16 +54,16 @@ pub fn readable(size: u64) -> String {if size == 0 {return "0 KB".to_string();}-+let units = ["B", "KB", "MB", "GB", "TB"];let mut size = size as f64;let mut unit = 0;-+while size >= 1024.0 && unit < units.len() - 1 {size /= 1024.0;unit += 1;}-+if unit == 0 {format!("{:.0} {}", size, units[unit])} else if units[unit] == "GB" || units[unit] == "TB" {@@ -74,9 +74,12 @@ pub fn readable(size: u64) -> String {}pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, String> {- info!("Calculating disk usage for directory: {}", screenpipe_dir.display());+ info!(+ "Calculating disk usage for directory: {}",+ screenpipe_dir.display()+ );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()),@@ -105,16 +108,19 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, Slet mut total_audio_size: u64 = 0;// Calculate total data size- info!("Calculating total data size for: {}", screenpipe_dir.display());+ info!(+ "Calculating total data size for: {}",+ screenpipe_dir.display()+ );let total_data_size = match directory_size(screenpipe_dir).map_err(|e| e.to_string())? {Some(size) => {info!("Total data size: {} bytes", size);readable(size)- },+ }None => {warn!("Could not calculate total data size");"---".to_string()- },+ }};// Calculate cache size@@ -123,17 +129,21 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, SSome(size) => {info!("Total cache size: {} bytes", size);readable(size)- },+ }None => {warn!("Could not calculate cache size");"---".to_string()- },+ }};// Calculate individual media file sizes recursivelyif data_dir.exists() {info!("Scanning data directory recursively for media files");- fn scan_media_files(dir: &Path, video_size: &mut u64, audio_size: &mut u64) -> io::Result<()> {+ fn scan_media_files(+ dir: &Path,+ video_size: &mut u64,+ audio_size: &mut u64,+ ) -> io::Result<()> {for entry in fs::read_dir(dir)? {let entry = entry?;let path = entry.path();@@ -143,25 +153,29 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, S} else if path.is_file() {let size = entry.metadata()?.len();let file_name = path.file_name().unwrap().to_string_lossy().to_string();-+// Classify files based on extension and name patterns- let extension = path.extension()+ let extension = path+ .extension().and_then(|ext| ext.to_str()).unwrap_or("").to_lowercase();-+match extension.as_str() {// Audio file extensions"mp3" | "wav" | "flac" | "aac" | "ogg" | "m4a" | "wma" => {*audio_size += size;- },+ }// Video file extensions- "mp4" | "avi" | "mkv" | "mov" | "wmv" | "flv" | "webm" | "m4v" => {+ "avi" | "mkv" | "mov" | "wmv" | "flv" | "webm" | "m4v" => {*video_size += size;- },+ }// Fallback to filename patterns for files without clear extensions_ => {- if file_name.contains("input") || file_name.contains("output") || file_name.contains("audio") {+ if file_name.contains("input")+ || file_name.contains("output")+ || file_name.contains("audio")+ {*audio_size += size;} else if file_name.contains("video") || file_name.contains("screen") {*video_size += size;@@ -175,12 +189,15 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, S}Ok(())}-+if let Err(e) = scan_media_files(&data_dir, &mut total_video_size, &mut total_audio_size) {warn!("Error scanning media files: {}", e);}-- info!("Video files total: {} bytes, Audio files total: {} bytes", total_video_size, total_audio_size);++ info!(+ "Video files total: {} bytes, Audio files total: {} bytes",+ total_video_size, total_audio_size+ );} else {warn!("Data directory does not exist: {}", data_dir.display());}@@ -196,7 +213,8 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, Slet mut sys = System::new();sys.refresh_disks_list();let path_obj = Path::new(&screenpipe_dir);- let available = sys.disks()+ let available = sys+ .disks().iter().find(|disk| path_obj.starts_with(disk.mount_point())).map(|disk| disk.available_space())@@ -224,7 +242,10 @@ pub async fn disk_usage(screenpipe_dir: &PathBuf) -> Result<Option<DiskUsage>, Susage: disk_usage.clone(),};- info!("Writing disk usage cache file: {}", cache_file.to_string_lossy());+ info!(+ "Writing disk usage cache file: {}",+ cache_file.to_string_lossy()+ );if let Err(e) = fs::write(&cache_file, serde_json::to_string_pretty(&cached).unwrap()) {warn!("Failed to write cache file: {}", e);diff --git a/openrewind/src-tauri/src/main.rs b/openrewind/src-tauri/src/main.rsindex 9497cdc95..97f4bf917 100755--- a/openrewind/src-tauri/src/main.rs+++ b/openrewind/src-tauri/src/main.rs@@ -266,7 +266,8 @@ pub struct LogFile {#[tauri::command]#[specta::specta]async fn get_log_files(app: AppHandle) -> Result<Vec<LogFile>, String> {- let data_dir = get_data_dir(&app).map_err(|e| e.to_string())?;+ let data_dir = get_openrewind_data_dir(&app).map_err(|e| e.to_string())?;+ let openrewind_data_dir = get_data_dir(&app).map_err(|e| e.to_string())?;let mut log_files = Vec::new();// Collect all entries first@@ -274,6 +275,10 @@ async fn get_log_files(app: AppHandle) -> Result<Vec<LogFile>, String> {let mut dir = tokio::fs::read_dir(&data_dir).await.map_err(|e| e.to_string())?;+ let mut openrewind_dir = tokio::fs::read_dir(&openrewind_data_dir)+ .await+ .map_err(|e| e.to_string())?;+while let Some(entry) = dir.next_entry().await.map_err(|e| e.to_string())? {// Get metadata immediately for each entryif let Ok(metadata) = entry.metadata().await {@@ -281,6 +286,13 @@ async fn get_log_files(app: AppHandle) -> Result<Vec<LogFile>, String> {}}+ while let Some(entry) = openrewind_dir.next_entry().await.map_err(|e| e.to_string())? {+ // Get metadata immediately for each entry+ if let Ok(metadata) = entry.metadata().await {+ entries.push((entry, metadata));+ }+ }+// Sort by modified time descending (newest first)entries.sort_by_key(|(_, metadata)| {std::cmp::Reverse(@@ -326,7 +338,7 @@ fn get_data_dir(app: &tauri::AppHandle) -> anyhow::Result<PathBuf> {let store = get_store(app, None)?;- let default_path = app.path().home_dir().unwrap().join(".openrewind");+ let default_path = app.path().home_dir().unwrap().join(".screenpipe");let data_dir = store.get("dataDir")@@ -340,6 +352,11 @@ fn get_data_dir(app: &tauri::AppHandle) -> anyhow::Result<PathBuf> {}}+fn get_openrewind_data_dir(app: &tauri::AppHandle) -> anyhow::Result<PathBuf> {+ let default_path = app.path().home_dir().unwrap().join(".openrewind");+ Ok(default_path)+}+use tokio::time::{sleep, Duration};#[tauri::command]@@ -728,7 +745,7 @@ async fn main() {.filename_suffix("log").max_log_files(5).build(- get_data_dir(app.handle())+ get_openrewind_data_dir(app.handle()).unwrap_or_else(|_| dirs::home_dir().unwrap().join(".openrewind")),)?;diff --git a/openrewind/src-tauri/src/window_api.rs b/openrewind/src-tauri/src/window_api.rsindex c3b2c497b..65d07943a 100644--- a/openrewind/src-tauri/src/window_api.rs+++ b/openrewind/src-tauri/src/window_api.rs@@ -327,7 +327,7 @@ impl ShowRewindWindow {let monitor = app.primary_monitor().unwrap().unwrap();let size = monitor.size();- let builder = self.window_builder(app, "/").hidden_title(true).visible_on_all_workspaces(true).always_on_top(true).decorations(false).skip_taskbar(true).focused(false).transparent(true).inner_size(size.width as f64, size.height as f64);+ let builder = self.window_builder(app, "/").hidden_title(true).visible_on_all_workspaces(true).always_on_top(true).decorations(false).skip_taskbar(true).focused(false).transparent(true).visible(false).inner_size(size.width as f64, size.height as f64);let window = builder.build()?;#[cfg(target_os = "macos")]