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

fix: power profile jpeg_quality was never applied to SnapshotWriter

jiachenb9b8c93d4bc2
diff --git a/Cargo.lock b/Cargo.lock
index 48ffc4206..37115cebc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -407,9 +407,9 @@ dependencies = [
[[package]]
name = "async-signal"
-version = "0.2.13"
+version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43c070bbf59cd3570b6b2dd54cd772527c7c3620fce8be898406dd3ed6adc64c"
+checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"
dependencies = [
"async-io",
"async-lock",
@@ -1140,7 +1140,7 @@ dependencies = [
[[package]]
name = "cidre"
version = "0.15.0"
-source = "git+https://github.com/yury/cidre.git#4b0f590028051f1b98c325405f119cb6f3e95580"
+source = "git+https://github.com/yury/cidre.git#ee0a48a2f8be4b4433e34db06bee46c3346a91a8"
dependencies = [
"cc",
"cidre-macros 0.5.0",
@@ -2376,9 +2376,9 @@ dependencies = [
[[package]]
name = "fastrand"
-version = "2.3.0"
+version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
+checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
[[package]]
name = "fax"
@@ -3765,9 +3765,9 @@ checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8"
[[package]]
name = "lettre"
-version = "0.11.20"
+version = "0.11.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "471816f3e24b85e820dee02cde962379ea1a669e5242f19c61bcbcffedf4c4fb"
+checksum = "dabda5859ee7c06b995b9d1165aa52c39110e079ef609db97178d86aeb051fa7"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -5495,7 +5495,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "986d2e952779af96ea048f160fd9194e1751b4faea78bcf3ceb456efe008088e"
dependencies = [
"der 0.8.0",
- "spki 0.8.0-rc.4",
+ "spki 0.8.0",
]
[[package]]
@@ -5532,7 +5532,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12922b6296c06eb741b02d7b5161e3aaa22864af38dfa025a1a3ba3f68c84577"
dependencies = [
"der 0.8.0",
- "spki 0.8.0-rc.4",
+ "spki 0.8.0",
]
[[package]]
@@ -5704,7 +5704,7 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
dependencies = [
- "toml_edit 0.25.10+spec-1.1.0",
+ "toml_edit 0.25.11+spec-1.1.0",
]
[[package]]
@@ -6305,7 +6305,7 @@ dependencies = [
"rand_core 0.10.0-rc-3",
"sha2 0.11.0",
"signature 3.0.0-rc.6",
- "spki 0.8.0-rc.4",
+ "spki 0.8.0",
"zeroize",
]
@@ -7126,9 +7126,9 @@ checksum = "689224d06523904ebcc9b482c6a3f4f7fb396096645c4cd10c0d2ff7371a34d3"
[[package]]
name = "semver"
-version = "1.0.27"
+version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
+checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "sentry"
@@ -7609,9 +7609,9 @@ dependencies = [
[[package]]
name = "spki"
-version = "0.8.0-rc.4"
+version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8baeff88f34ed0691978ec34440140e1572b68c7dd4a495fd14a3dc1944daa80"
+checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f"
dependencies = [
"base64ct",
"der 0.8.0",
@@ -8611,9 +8611,9 @@ dependencies = [
[[package]]
name = "toml_edit"
-version = "0.25.10+spec-1.1.0"
+version = "0.25.11+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a82418ca169e235e6c399a84e395ab6debeb3bc90edc959bf0f48647c6a32d1b"
+checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b"
dependencies = [
"indexmap 2.13.1",
"toml_datetime 1.1.1+spec-1.1.0",
diff --git a/crates/screenpipe-config/src/recording.rs b/crates/screenpipe-config/src/recording.rs
index 89ad0fb92..4fdd5cd15 100644
--- a/crates/screenpipe-config/src/recording.rs
+++ b/crates/screenpipe-config/src/recording.rs
@@ -117,6 +117,12 @@ pub struct RecordingSettings {
#[serde(rename = "videoQuality")]
pub video_quality: String,
+ /// Maximum width for stored snapshots. Images wider than this are downscaled
+ /// (preserving aspect ratio) before JPEG encoding. 0 = no limit (store at
+ /// native resolution). Default: 1920.
+ #[serde(rename = "maxSnapshotWidth", default = "default_max_snapshot_width")]
+ pub max_snapshot_width: u32,
+
// ── Filters ────────────────────────────────────────────────────────
/// Window titles to exclude from capture.
#[serde(rename = "ignoredWindows")]
@@ -294,6 +300,7 @@ impl Default for RecordingSettings {
monitor_ids: vec![],
use_all_monitors: true,
video_quality: "balanced".to_string(),
+ max_snapshot_width: default_max_snapshot_width(),
ignored_windows: vec![],
included_windows: vec![],
ignored_urls: vec![],
@@ -330,6 +337,10 @@ fn default_true() -> bool {
true
}
+fn default_max_snapshot_width() -> u32 {
+ 1920
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/screenpipe-engine/src/event_driven_capture.rs b/crates/screenpipe-engine/src/event_driven_capture.rs
index c98d00cc6..b60e54831 100644
--- a/crates/screenpipe-engine/src/event_driven_capture.rs
+++ b/crates/screenpipe-engine/src/event_driven_capture.rs
@@ -378,6 +378,7 @@ pub async fn event_driven_capture_loop(
state.config.min_capture_interval_ms = profile.min_capture_interval_ms;
state.config.idle_capture_interval_ms = profile.idle_capture_interval_ms;
state.config.jpeg_quality = profile.jpeg_quality;
+ snapshot_writer.set_quality(profile.jpeg_quality);
visual_check_interval = Duration::from_millis(profile.visual_check_interval_ms);
visual_change_threshold = profile.visual_change_threshold;
visual_check_enabled = profile.visual_check_interval_ms > 0;
diff --git a/crates/screenpipe-engine/src/recording_config.rs b/crates/screenpipe-engine/src/recording_config.rs
index 5c931d26f..04d54e6bb 100644
--- a/crates/screenpipe-engine/src/recording_config.rs
+++ b/crates/screenpipe-engine/src/recording_config.rs
@@ -106,6 +106,9 @@ pub struct RecordingConfig {
/// Per-day schedule rules (only used when schedule_enabled is true).
pub schedule_rules: Vec<screenpipe_config::ScheduleRule>,
+
+ /// Maximum width for stored snapshots (0 = no limit). Default: 1920.
+ pub max_snapshot_width: u32,
}
impl RecordingConfig {
@@ -192,6 +195,7 @@ impl RecordingConfig {
.unwrap_or_default(),
schedule_enabled: settings.schedule_enabled,
schedule_rules: settings.schedule_rules.clone(),
+ max_snapshot_width: settings.max_snapshot_width,
}
}
@@ -250,6 +254,7 @@ impl RecordingConfig {
ignore_incognito_windows: self.ignore_incognito_windows,
pause_on_drm_content: self.pause_on_drm_content,
languages: self.languages.clone(),
+ max_snapshot_width: self.max_snapshot_width,
}
}
}
diff --git a/crates/screenpipe-engine/src/vision_manager/manager.rs b/crates/screenpipe-engine/src/vision_manager/manager.rs
index 712e52458..5571b248a 100644
--- a/crates/screenpipe-engine/src/vision_manager/manager.rs
+++ b/crates/screenpipe-engine/src/vision_manager/manager.rs
@@ -39,6 +39,8 @@ pub struct VisionManagerConfig {
pub pause_on_drm_content: bool,
/// Languages for OCR recognition.
pub languages: Vec<screenpipe_core::Language>,
+ /// Maximum width for stored snapshots (0 = no limit, store at native res).
+ pub max_snapshot_width: u32,
}
/// Status of the VisionManager
@@ -242,10 +244,17 @@ impl VisionManager {
let output_path = self.config.output_path.clone();
let device_name = format!("monitor_{}", monitor_id);
- // Create snapshot writer for this monitor's data directory
+ // Create snapshot writer for this monitor's data directory.
+ // Use current power profile's JPEG quality instead of hardcoded 80.
+ let initial_jpeg_quality = self
+ .power_profile_rx
+ .as_ref()
+ .map(|rx| rx.borrow().jpeg_quality)
+ .unwrap_or(80);
let snapshot_writer = Arc::new(SnapshotWriter::new(
format!("{}/data", output_path),
- 80, // JPEG quality
+ initial_jpeg_quality,
+ self.config.max_snapshot_width,
));
// Create activity feed for this monitor
diff --git a/crates/screenpipe-screen/src/snapshot_writer.rs b/crates/screenpipe-screen/src/snapshot_writer.rs
index 906a37a19..af83fab63 100644
--- a/crates/screenpipe-screen/src/snapshot_writer.rs
+++ b/crates/screenpipe-screen/src/snapshot_writer.rs
@@ -10,30 +10,46 @@
use anyhow::Result;
use chrono::{DateTime, Utc};
use image::codecs::jpeg::JpegEncoder;
+use image::imageops::FilterType;
use image::DynamicImage;
use std::fs;
use std::io::{BufWriter, Write};
use std::path::{Path, PathBuf};
+use std::sync::atomic::{AtomicU8, AtomicU32, Ordering};
use tracing::{debug, error};
/// Writes JPEG snapshots to disk for event-driven capture.
pub struct SnapshotWriter {
base_dir: PathBuf,
- quality: u8,
+ quality: AtomicU8,
+ /// Maximum width for stored snapshots (0 = no limit).
+ max_width: AtomicU32,
}
impl SnapshotWriter {
/// Create a new SnapshotWriter.
///
/// - `base_dir`: root data directory (e.g., `~/.screenpipe/data`)
- /// - `quality`: JPEG quality 1-100 (default 80)
- pub fn new(base_dir: impl Into<PathBuf>, quality: u8) -> Self {
+ /// - `quality`: JPEG quality 1-100
+ /// - `max_width`: max snapshot width in pixels (0 = no limit)
+ pub fn new(base_dir: impl Into<PathBuf>, quality: u8, max_width: u32) -> Self {
Self {
base_dir: base_dir.into(),
- quality: quality.clamp(1, 100),
+ quality: AtomicU8::new(quality.clamp(1, 100)),
+ max_width: AtomicU32::new(max_width),
}
}
+ /// Update JPEG quality at runtime (called by power manager).
+ pub fn set_quality(&self, quality: u8) {
+ self.quality.store(quality.clamp(1, 100), Ordering::Relaxed);
+ }
+
+ /// Update maximum snapshot width at runtime (0 = no limit).
+ pub fn set_max_width(&self, width: u32) {
+ self.max_width.store(width, Ordering::Relaxed);
+ }
+
/// Write a screenshot as JPEG. Returns the absolute path to the written file.
///
/// File layout: `{base_dir}/YYYY-MM-DD/{timestamp_ms}_m{monitor_id}.jpg`
@@ -52,19 +68,34 @@ impl SnapshotWriter {
let filename = format!("{}_m{}.jpg", timestamp_ms, monitor_id);
let path = date_dir.join(&filename);
+ let quality = self.quality.load(Ordering::Relaxed);
+ let max_w = self.max_width.load(Ordering::Relaxed);
+
+ // Downscale if image exceeds max_width (preserving aspect ratio).
+ // Use a reference to avoid cloning the full image buffer when no resize is needed.
+ let resized;
+ let img: &DynamicImage = if max_w > 0 && image.width() > max_w {
+ resized = image.resize(max_w, u32::MAX, FilterType::Triangle);
+ &resized
+ } else {
+ image
+ };
+
let file = fs::File::create(&path)?;
let mut writer = BufWriter::new(file);
- let mut encoder = JpegEncoder::new_with_quality(&mut writer, self.quality);
- encoder.encode_image(image)?;
+ let mut encoder = JpegEncoder::new_with_quality(&mut writer, quality);
+ encoder.encode_image(img)?;
writer.flush()?;
writer.get_ref().sync_all()?;
debug!(
- "snapshot written: {} ({}x{}, q={})",
+ "snapshot written: {} ({}x{} -> {}x{}, q={})",
path.display(),
image.width(),
image.height(),
- self.quality
+ img.width(),
+ img.height(),
+ quality
);
Ok(path)
@@ -126,7 +157,7 @@ mod tests {
#[test]
fn test_write_creates_jpeg() {
let tmp = TempDir::new().unwrap();
- let writer = SnapshotWriter::new(tmp.path(), 80);
+ let writer = SnapshotWriter::new(tmp.path(), 80, 0);
let img = test_image(1920, 1080);
let now = Utc::now();
@@ -145,7 +176,7 @@ mod tests {
#[test]
fn test_write_creates_date_directory() {
let tmp = TempDir::new().unwrap();
- let writer = SnapshotWriter::new(tmp.path(), 80);
+ let writer = SnapshotWriter::new(tmp.path(), 80, 0);
let img = test_image(100, 100);
let now = Utc::now();
@@ -158,7 +189,7 @@ mod tests {
#[test]
fn test_write_includes_monitor_id() {
let tmp = TempDir::new().unwrap();
- let writer = SnapshotWriter::new(tmp.path(), 80);
+ let writer = SnapshotWriter::new(tmp.path(), 80, 0);
let img = test_image(100, 100);
let now = Utc::now();
@@ -169,10 +200,10 @@ mod tests {
#[test]
fn test_quality_clamped() {
- let writer = SnapshotWriter::new("/tmp", 150);
- assert_eq!(writer.quality, 100);
+ let writer = SnapshotWriter::new("/tmp", 150, 0);
+ assert_eq!(writer.quality.load(Ordering::Relaxed), 100);
- let writer = SnapshotWriter::new("/tmp", 0);
- assert_eq!(writer.quality, 1);
+ let writer = SnapshotWriter::new("/tmp", 0, 0);
+ assert_eq!(writer.quality.load(Ordering::Relaxed), 1);
}
}