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

Bump app to v2.2.52 — reduce compaction CPU: JPEG passthrough, pacing, battery skip, Windows idle priority

Louis Beaumont0f35e3cdbf1f
diff --git a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
index 1c268b3f6..a122110a5 100644
--- a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx
@@ -299,6 +299,9 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
const [appFilter, setAppFilter] = useState<string | null>(null);
const [speakerAppFilter, setSpeakerAppFilter] = useState<string | null>(null);
const [domainFilter, setDomainFilter] = useState<string | null>(null);
+ // Time filter — stores the date string (YYYY-MM-DD) from a time range chip
+ const [timeFilter, setTimeFilter] = useState<string | null>(null);
+ const [speakerTimeFilter, setSpeakerTimeFilter] = useState<string | null>(null);
// Pagination
const [ocrOffset, setOcrOffset] = useState(0);
@@ -328,12 +331,13 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
// --- Facet state (loaded async, independent of paginated results) ---
const [facetApps, setFacetApps] = useState<[string, number][]>([]);
const [facetDomains, setFacetDomains] = useState<[string, number][]>([]);
- const [facetTimeRanges, setFacetTimeRanges] = useState<{ label: string; timestamp: string; count: number }[]>([]);
+ const [facetTimeRanges, setFacetTimeRanges] = useState<{ label: string; dateKey: string; timestamp: string; count: number }[]>([]);
// Build time range labels from raw rows
const buildTimeRanges = useCallback((rows: { timestamp: string; count: number }[]) => {
return rows.map(r => {
const d = new Date(r.timestamp);
+ const dateKey = format(d, "yyyy-MM-dd");
let label: string;
if (isToday(d)) {
label = format(d, "h a");
@@ -342,7 +346,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
} else {
label = format(d, "MMM d");
}
- return { label, timestamp: r.timestamp, count: r.count };
+ return { label, dateKey, timestamp: r.timestamp, count: r.count };
}).slice(0, 10);
}, []);
@@ -422,17 +426,18 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
// Speaker time ranges (from loaded transcriptions — these are small enough)
const speakerTimeRanges = useMemo(() => {
if (speakerTranscriptions.length === 0) return [];
- const buckets = new Map<string, { label: string; timestamp: string; count: number }>();
+ const buckets = new Map<string, { label: string; dateKey: string; timestamp: string; count: number }>();
for (const t of speakerTranscriptions) {
const d = new Date(t.timestamp);
if (isNaN(d.getTime())) continue;
const key = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
if (!buckets.has(key)) {
+ const dateKey = format(d, "yyyy-MM-dd");
let label: string;
if (isToday(d)) label = format(d, "h a");
else if (isYesterday(d)) label = "yesterday " + format(d, "h a");
else label = format(d, "MMM d");
- buckets.set(key, { label, timestamp: t.timestamp, count: 1 });
+ buckets.set(key, { label, dateKey, timestamp: t.timestamp, count: 1 });
} else {
buckets.get(key)!.count++;
}
@@ -466,14 +471,21 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
return [...counts.entries()].sort((a, b) => b[1] - a[1]);
}, [transcriptionFrames]);
- // Filter speaker transcriptions by app
+ // Filter speaker transcriptions by app and time
const filteredSpeakerTranscriptions = useMemo(() => {
- if (!speakerAppFilter) return speakerTranscriptions;
- return speakerTranscriptions.filter(t => {
+ let items = speakerTranscriptions;
+ if (speakerAppFilter) items = items.filter(t => {
const info = transcriptionFrames.get(t.timestamp);
return info?.app_name === speakerAppFilter;
});
- }, [speakerTranscriptions, speakerAppFilter, transcriptionFrames]);
+ if (speakerTimeFilter) items = items.filter(t => t.timestamp.startsWith(speakerTimeFilter));
+ return items;
+ }, [speakerTranscriptions, speakerAppFilter, speakerTimeFilter, transcriptionFrames]);
+
+ const matchesTimeFilter = useCallback((timestamp: string) => {
+ if (!timeFilter) return true;
+ return timestamp.startsWith(timeFilter);
+ }, [timeFilter]);
const filteredResults = useMemo(() => {
let results = searchResults;
@@ -481,8 +493,9 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
if (domainFilter) results = results.filter(r => {
try { return new URL(r.url).hostname.replace(/^www\./, "") === domainFilter; } catch { return false; }
});
+ if (timeFilter) results = results.filter(r => matchesTimeFilter(r.timestamp));
return results;
- }, [searchResults, appFilter, domainFilter]);
+ }, [searchResults, appFilter, domainFilter, timeFilter, matchesTimeFilter]);
const filteredGroups = useMemo(() => {
let groups = searchGroups;
@@ -490,6 +503,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
if (domainFilter) groups = groups.filter(g => {
try { return new URL(g.representative.url).hostname.replace(/^www\./, "") === domainFilter; } catch { return false; }
});
+ if (timeFilter) groups = groups.filter(g => matchesTimeFilter(g.representative.timestamp));
return groups;
}, [searchGroups, appFilter, domainFilter]);
@@ -510,6 +524,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
clearHighlight();
setAppFilter(null);
setDomainFilter(null);
+ setTimeFilter(null);
setContentFilter("all");
setSpeakerResults([]);
setTagResults([]);
@@ -548,6 +563,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
setTagResults([]);
setAppFilter(null);
setDomainFilter(null);
+ setTimeFilter(null);
return;
}
@@ -560,6 +576,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
setAppFilter(null);
setDomainFilter(null);
+ setTimeFilter(null);
setContentFilter("all");
setTagResults([]);
setOcrOffset(0);
@@ -789,6 +806,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
setSelectedSpeaker(null);
setSpeakerTranscriptions([]);
setSpeakerAppFilter(null);
+ setSpeakerTimeFilter(null);
setSelectedTranscriptionIndex(0);
setTranscriptionOffset(0);
setHasMoreTranscriptions(true);
@@ -1049,17 +1067,31 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
</div>
)}
- {/* Time range chips for speaker transcriptions */}
+ {/* Time range filter chips for speaker transcriptions */}
{speakerTimeRanges.length > 1 && (
<div className="flex gap-1.5 mb-3 overflow-x-auto scrollbar-hide pb-0.5">
+ <button
+ onClick={() => { setSpeakerTimeFilter(null); setSelectedTranscriptionIndex(0); }}
+ className={cn(
+ "px-2.5 py-1 text-[11px] rounded-full border transition-colors flex items-center gap-1.5 whitespace-nowrap shrink-0",
+ !speakerTimeFilter
+ ? "bg-foreground text-background border-foreground"
+ : "border-border text-muted-foreground hover:border-foreground/40"
+ )}
+ >
+ <Clock className="w-3 h-3" />
+ all dates
+ </button>
{speakerTimeRanges.map((range) => (
<button
- key={range.timestamp}
- onClick={() => {
- onNavigateToTimestamp(range.timestamp);
- onClose();
- }}
- className="px-2.5 py-1 text-[11px] rounded-full border border-border text-muted-foreground hover:border-foreground/40 transition-colors flex items-center gap-1 whitespace-nowrap shrink-0"
+ key={range.dateKey}
+ onClick={() => { setSpeakerTimeFilter(speakerTimeFilter === range.dateKey ? null : range.dateKey); setSelectedTranscriptionIndex(0); }}
+ className={cn(
+ "px-2.5 py-1 text-[11px] rounded-full border transition-colors flex items-center gap-1 whitespace-nowrap shrink-0",
+ speakerTimeFilter === range.dateKey
+ ? "bg-foreground text-background border-foreground"
+ : "border-border text-muted-foreground hover:border-foreground/40"
+ )}
>
<Clock className="w-3 h-3" />
{range.label} ({range.count})
@@ -1394,17 +1426,31 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =
</div>
)}
- {/* Time range chips */}
+ {/* Time range filter chips */}
{timeRanges.length > 1 && (
<div className="flex gap-1.5 mb-3 overflow-x-auto scrollbar-hide pb-0.5">
+ <button
+ onClick={() => { setTimeFilter(null); setSelectedIndex(0); }}
+ className={cn(
+ "px-2.5 py-1 text-[11px] rounded-full border transition-colors flex items-center gap-1.5 whitespace-nowrap shrink-0",
+ !timeFilter
+ ? "bg-foreground text-background border-foreground"
+ : "border-border text-muted-foreground hover:border-foreground/40"
+ )}
+ >
+ <Clock className="w-3 h-3" />
+ all dates
+ </button>
{timeRanges.map((range) => (
<button
- key={range.timestamp}
- onClick={() => {
- onNavigateToTimestamp(range.timestamp);
- onClose();
- }}
- className="px-2.5 py-1 text-[11px] rounded-full border border-border text-muted-foreground hover:border-foreground/40 transition-colors flex items-center gap-1 whitespace-nowrap shrink-0"
+ key={range.dateKey}
+ onClick={() => { setTimeFilter(timeFilter === range.dateKey ? null : range.dateKey); setSelectedIndex(0); }}
+ className={cn(
+ "px-2.5 py-1 text-[11px] rounded-full border transition-colors flex items-center gap-1 whitespace-nowrap shrink-0",
+ timeFilter === range.dateKey
+ ? "bg-foreground text-background border-foreground"
+ : "border-border text-muted-foreground hover:border-foreground/40"
+ )}
>
<Clock className="w-3 h-3" />
{range.label} ({range.count})
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index d3141cd3d..59834fdbf 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.2.51"
+version = "2.2.52"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""
diff --git a/crates/screenpipe-server/src/snapshot_compaction.rs b/crates/screenpipe-server/src/snapshot_compaction.rs
index 3dc17c8ce..f7afc9359 100644
--- a/crates/screenpipe-server/src/snapshot_compaction.rs
+++ b/crates/screenpipe-server/src/snapshot_compaction.rs
@@ -55,6 +55,19 @@ pub fn start_snapshot_compaction(
loop {
let state = power_manager.current_state().await;
+ // Skip compaction on battery — disk space isn't urgent enough to drain battery
+ if !state.on_ac {
+ debug!("snapshot compaction: skipping — on battery");
+ tokio::select! {
+ _ = tokio::time::sleep(std::time::Duration::from_secs(POLL_INTERVAL_SECS)) => {}
+ _ = shutdown_rx.recv() => {
+ info!("snapshot compaction worker shutting down");
+ break;
+ }
+ }
+ continue;
+ }
+
// Adapt batch size and delay based on thermal state
let (chunk_size, inter_chunk_delay_secs) = match state.thermal_state {
ThermalState::Nominal | ThermalState::Fair => (MAX_FRAMES_PER_CHUNK, 0u64),
@@ -214,18 +227,13 @@ async fn compact_chunk(
jpeg_total_bytes as f64 / 1_048_576.0
);
- // Encode JPEGs → MP4 via ffmpeg (low-priority, capped threads, raw RGB pipe)
- let mut child =
- start_ffmpeg_lowpri(&mp4_path_str, fps, video_quality, frame_w, frame_h).await?;
+ // Encode JPEGs → MP4 via ffmpeg (low-priority, capped threads, JPEG passthrough)
+ let mut child = start_ffmpeg_lowpri(&mp4_path_str, fps, video_quality).await?;
let mut stdin = child
.stdin
.take()
.ok_or_else(|| anyhow::anyhow!("ffmpeg stdin not available"))?;
- // Pre-calculate target dimensions (must match what ffmpeg expects)
- let target_w = (frame_w / 2) * 2;
- let target_h = (frame_h / 2) * 2;
-
let mut encoded_count = 0u32;
for (_, snapshot_path, _) in frames {
let jpeg_path = Path::new(snapshot_path);
@@ -234,24 +242,19 @@ async fn compact_chunk(
continue;
}
- // Decode JPEG → raw RGB bytes (no PNG re-encode needed)
- match image::open(jpeg_path) {
- Ok(img) => {
- // Resize if dimensions don't match (handles mixed-resolution edge case)
- let img = if img.width() != target_w || img.height() != target_h {
- img.resize_exact(target_w, target_h, image::imageops::FilterType::Nearest)
- } else {
- img
- };
- let rgb = img.to_rgb8();
- if let Err(e) = write_frame_to_ffmpeg(&mut stdin, rgb.as_raw()).await {
+ // Pass raw JPEG bytes directly to ffmpeg (no Rust-side decode needed)
+ match tokio::fs::read(jpeg_path).await {
+ Ok(jpeg_bytes) => {
+ if let Err(e) = write_frame_to_ffmpeg(&mut stdin, &jpeg_bytes).await {
error!("failed to write frame to ffmpeg: {}", e);
break;
}
encoded_count += 1;
+ // Pace writes to avoid CPU spikes — spread encoding over time
+ tokio::time::sleep(std::time::Duration::from_millis(50)).await;
}
Err(e) => {
- warn!("failed to open snapshot {}: {}", snapshot_path, e);
+ warn!("failed to read snapshot {}: {}", snapshot_path, e);
continue;
}
}
@@ -326,24 +329,19 @@ async fn compact_chunk(
}
/// Spawn ffmpeg with low CPU priority for background compaction.
-/// Uses `nice` on unix to lower scheduling priority, limits x265
-/// internal thread pool to 1, and caps ffmpeg threads to 1.
+/// Uses `nice` on unix / IDLE_PRIORITY_CLASS on Windows.
+/// Accepts JPEG passthrough (image2pipe mjpeg) so Rust doesn't need to decode.
+/// Limits x265 internal threading to 1 pool with 1 thread.
async fn start_ffmpeg_lowpri(
output_file: &str,
fps: f64,
video_quality: &str,
- width: u32,
- height: u32,
) -> Result<tokio::process::Child> {
let ffmpeg_path =
screenpipe_core::find_ffmpeg_path().ok_or_else(|| anyhow::anyhow!("ffmpeg not found"))?;
let fps_str = fps.to_string();
let crf = video_quality_to_crf(video_quality);
- // Ensure even dimensions for h265
- let w = (width / 2) * 2;
- let h = (height / 2) * 2;
- let size_str = format!("{}x{}", w, h);
// On unix, wrap with `nice -n 19` for lowest scheduling priority
#[cfg(unix)]
@@ -359,15 +357,15 @@ async fn start_ffmpeg_lowpri(
command
.args([
"-f",
- "rawvideo",
- "-pixel_format",
- "rgb24",
- "-video_size",
- &size_str,
+ "image2pipe",
+ "-vcodec",
+ "mjpeg",
"-r",
&fps_str,
"-i",
"-",
+ "-vf",
+ "scale=trunc(iw/2)*2:trunc(ih/2)*2",
"-vcodec",
"libx265",
"-tag:v",
@@ -393,8 +391,11 @@ async fn start_ffmpeg_lowpri(
#[cfg(windows)]
{
+ // IDLE_PRIORITY_CLASS: only run when CPU is otherwise idle
+ // CREATE_NO_WINDOW: no console window
+ const IDLE_PRIORITY_CLASS: u32 = 0x00000040;
const CREATE_NO_WINDOW: u32 = 0x08000000;
- command.creation_flags(CREATE_NO_WINDOW);
+ command.creation_flags(IDLE_PRIORITY_CLASS | CREATE_NO_WINDOW);
}
Ok(command.spawn()?)