Skip to content

Commit 25d3690

Browse files
committed
fix #183
1 parent c028387 commit 25d3690

15 files changed

+232
-547
lines changed

screenpipe-server/src/bin/screenpipe-server.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ async fn main() -> anyhow::Result<()> {
8787
if cli.debug {
8888
builder.filter_module("screenpipe", LevelFilter::Debug);
8989
}
90-
// Example usage of the new flag
91-
if cli.save_text_files {
92-
debug!("Text files will be saved.");
93-
}
9490

9591
let local_data_dir = get_base_dir(cli.data_dir)?;
9692
let local_data_dir_clone = local_data_dir.clone();
@@ -134,7 +130,7 @@ async fn main() -> anyhow::Result<()> {
134130
if cli.list_monitors {
135131
println!("Available monitors:");
136132
for (_, monitor) in all_monitors.iter().enumerate() {
137-
println!(" {}. {:?}", monitor.id(), monitor);
133+
println!(" {}. {:?}", monitor.id, monitor);
138134
}
139135
return Ok(());
140136
}
@@ -238,7 +234,7 @@ async fn main() -> anyhow::Result<()> {
238234

239235
let warning_ocr_engine_clone = cli.ocr_engine.clone();
240236
let warning_audio_transcription_engine_clone = cli.audio_transcription_engine.clone();
241-
let monitor_id = cli.monitor_id.unwrap_or(all_monitors.first().unwrap().id());
237+
let monitor_id = cli.monitor_id.unwrap_or(all_monitors.first().unwrap().id);
242238

243239
// try to use the monitor selected, if not available throw an error
244240
get_monitor_by_id(monitor_id).await.unwrap_or_else(|| {
@@ -291,7 +287,6 @@ async fn main() -> anyhow::Result<()> {
291287
Duration::from_secs(cli.audio_chunk_duration),
292288
vision_control,
293289
audio_devices_control,
294-
cli.save_text_files,
295290
audio_transcription_engine,
296291
ocr_engine,
297292
friend_wearable_uid_clone, // Use the cloned version
@@ -374,7 +369,6 @@ async fn main() -> anyhow::Result<()> {
374369
println!("│ Port │ {:<34} │", cli.port);
375370
println!("│ Audio Disabled │ {:<34} │", cli.disable_audio);
376371
println!("│ Self Healing │ {:<34} │", cli.self_healing);
377-
println!("│ Save Text Files │ {:<34} │", cli.save_text_files);
378372
println!(
379373
"│ Audio Engine │ {:<34} │",
380374
format!("{:?}", warning_audio_transcription_engine_clone)

screenpipe-server/src/cli.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ pub struct Cli {
6464
/// 5 FPS = 150 GB / month
6565
/// Optimise based on your needs.
6666
/// Your screen rarely change more than 1 times within a second, right?
67-
#[cfg_attr(not(target_os = "macos"), arg(short, long, default_value_t = 1.0))]
68-
#[cfg_attr(target_os = "macos", arg(short, long, default_value_t = 0.2))]
69-
pub fps: f64, // ! not crazy about this (unconsistent behaviour across platforms) see https://github.com/mediar-ai/screenpipe/issues/173
67+
#[arg(short, long, default_value_t = 1)]
68+
pub fps: u32, // ! not crazy about this (unconsistent behaviour across platforms) see https://github.com/mediar-ai/screenpipe/issues/173
7069

7170
/// Audio chunk duration in seconds
7271
#[arg(short = 'd', long, default_value_t = 30)]
@@ -101,10 +100,6 @@ pub struct Cli {
101100
#[arg(long)]
102101
pub debug: bool,
103102

104-
/// Save text files
105-
#[arg(long, default_value_t = false)]
106-
pub save_text_files: bool,
107-
108103
/// Audio transcription engine to use.
109104
/// Deepgram is a very high quality cloud-based transcription service (free of charge on us for now), recommended for high quality audio.
110105
/// WhisperTiny is a local, lightweight transcription model, recommended for high data privacy.

screenpipe-server/src/core.rs

+23-40
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ use tokio::task::JoinHandle;
2121
pub async fn start_continuous_recording(
2222
db: Arc<DatabaseManager>,
2323
output_path: Arc<String>,
24-
fps: f64,
24+
fps: u32,
2525
audio_chunk_duration: Duration,
2626
vision_control: Arc<AtomicBool>,
2727
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
28-
save_text_files: bool,
2928
audio_transcription_engine: Arc<AudioTranscriptionEngine>,
3029
ocr_engine: Arc<OcrEngine>,
3130
friend_wearable_uid: Option<String>,
@@ -59,7 +58,6 @@ pub async fn start_continuous_recording(
5958
output_path_video,
6059
fps,
6160
is_running_video,
62-
save_text_files,
6361
ocr_engine,
6462
friend_wearable_uid_video,
6563
monitor_id,
@@ -99,9 +97,8 @@ pub async fn start_continuous_recording(
9997
async fn record_video(
10098
db: Arc<DatabaseManager>,
10199
output_path: Arc<String>,
102-
fps: f64,
100+
fps: u32,
103101
is_running: Arc<AtomicBool>,
104-
save_text_files: bool,
105102
ocr_engine: Arc<OcrEngine>,
106103
_friend_wearable_uid: Option<String>,
107104
monitor_id: u32,
@@ -125,52 +122,38 @@ async fn record_video(
125122
&output_path,
126123
fps,
127124
new_chunk_callback,
128-
save_text_files,
129125
Arc::clone(&ocr_engine),
130126
monitor_id,
131127
);
132128

133129
while is_running.load(Ordering::SeqCst) {
134130
if let Some(frame) = video_capture.ocr_frame_queue.pop() {
135-
for window_result in &frame.window_ocr_results {
136-
match db.insert_frame().await {
137-
Ok(frame_id) => {
138-
let text_json =
139-
serde_json::to_string(&window_result.text_json).unwrap_or_default();
140-
141-
let text = if use_pii_removal {
142-
&remove_pii(&window_result.text)
143-
} else {
144-
&window_result.text
145-
};
146-
if let Err(e) = db
147-
.insert_ocr_text(
148-
frame_id,
149-
text,
150-
&text_json,
151-
&window_result.app_name,
152-
&window_result.window_name,
153-
Arc::clone(&ocr_engine),
154-
window_result.focused, // Add this line
155-
)
156-
.await
157-
{
158-
error!(
159-
"Failed to insert OCR text: {}, skipping window {} of frame {}",
160-
e, window_result.window_name, frame_id
161-
);
162-
continue;
163-
}
164-
}
165-
Err(e) => {
166-
warn!("Failed to insert frame: {}", e);
167-
tokio::time::sleep(Duration::from_millis(100)).await;
131+
match db.insert_frame().await {
132+
Ok(frame_id) => {
133+
let text = if use_pii_removal {
134+
&remove_pii(&frame.ocr_results)
135+
} else {
136+
&frame.ocr_results
137+
};
138+
if let Err(e) = db
139+
.insert_ocr_text(frame_id, text, &frame.raw_json, Arc::clone(&ocr_engine))
140+
.await
141+
{
142+
error!(
143+
"Failed to insert OCR text: {}, skipping frame {}",
144+
e, frame_id
145+
);
168146
continue;
169147
}
170148
}
149+
Err(e) => {
150+
warn!("Failed to insert frame: {}", e);
151+
tokio::time::sleep(Duration::from_millis(100)).await;
152+
continue;
153+
}
171154
}
172155
}
173-
tokio::time::sleep(Duration::from_secs_f64(1.0 / fps)).await;
156+
tokio::time::sleep(Duration::from_millis(100)).await;
174157
}
175158

176159
Ok(())

screenpipe-server/src/db.rs

+13-37
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,16 @@ impl DatabaseManager {
337337
&self,
338338
frame_id: i64,
339339
text: &str,
340-
text_json: &str,
341-
app_name: &str,
342-
window_name: &str,
340+
raw_json: &str,
343341
ocr_engine: Arc<OcrEngine>,
344-
focused: bool,
345342
) -> Result<(), sqlx::Error> {
346343
const MAX_RETRIES: u32 = 3;
347344
const TIMEOUT_DURATION: TokioDuration = TokioDuration::from_secs(10);
348345

349346
for attempt in 1..=MAX_RETRIES {
350347
match timeout(
351348
TIMEOUT_DURATION,
352-
self.insert_ocr_text_old(
353-
frame_id,
354-
text,
355-
text_json,
356-
app_name,
357-
window_name,
358-
Arc::clone(&ocr_engine),
359-
focused,
360-
),
349+
self.insert_ocr_text_old(frame_id, text, raw_json, Arc::clone(&ocr_engine)),
361350
)
362351
.await
363352
{
@@ -459,39 +448,26 @@ impl DatabaseManager {
459448
&self,
460449
frame_id: i64,
461450
text: &str,
462-
text_json: &str,
463-
app_name: &str,
464-
window_name: &str,
451+
raw_json: &str,
465452
ocr_engine: Arc<OcrEngine>,
466-
focused: bool,
467453
) -> Result<(), sqlx::Error> {
468-
let display_window_name = if window_name.chars().count() > 20 {
469-
format!("{}...", window_name.chars().take(20).collect::<String>())
470-
} else {
471-
window_name.to_string()
472-
};
473-
474454
debug!(
475-
"Inserting OCR: frame_id {}, app {}, window {}, focused {}, text {}{}",
455+
"Inserting OCR: frame_id {}, text {}{}",
476456
frame_id,
477-
app_name,
478-
display_window_name,
479-
focused,
480457
text.replace('\n', " ").chars().take(60).collect::<String>(),
481458
if text.len() > 60 { "..." } else { "" },
482459
);
483460

484461
let mut tx = self.pool.begin().await?;
485-
sqlx::query("INSERT INTO ocr_text (frame_id, text, text_json, app_name, ocr_engine, window_name, focused) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)")
486-
.bind(frame_id)
487-
.bind(text)
488-
.bind(text_json)
489-
.bind(app_name)
490-
.bind(format!("{:?}", *ocr_engine))
491-
.bind(window_name)
492-
.bind(focused)
493-
.execute(&mut *tx)
494-
.await?;
462+
sqlx::query(
463+
"INSERT INTO ocr_text (frame_id, text, text_json, ocr_engine) VALUES (?1, ?2, ?3, ?4)",
464+
)
465+
.bind(frame_id)
466+
.bind(text)
467+
.bind(raw_json)
468+
.bind(format!("{:?}", *ocr_engine))
469+
.execute(&mut *tx)
470+
.await?;
495471

496472
tx.commit().await?;
497473
debug!("OCR text inserted into db successfully");

screenpipe-server/src/resource_monitor.rs

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ impl ResourceMonitor {
180180
let client = reqwest::Client::new();
181181
match client.get("http://localhost:3030/health").send().await {
182182
Ok(response) => {
183-
debug!("Health check response: {:?}", response);
184183
if response.status().is_success() {
185184
*self.health_check_failures.lock().await = 0;
186185
} else {

screenpipe-server/src/server.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ pub async fn api_list_monitors(
313313
let monitor_info: Vec<MonitorInfo> = monitors
314314
.into_iter()
315315
.map(|monitor| MonitorInfo {
316-
id: monitor.id(),
317-
name: monitor.name().to_string(),
318-
width: monitor.width(),
319-
height: monitor.height(),
320-
is_default: monitor.is_primary(),
316+
id: monitor.id,
317+
name: monitor.name,
318+
width: monitor.width,
319+
height: monitor.height,
320+
is_default: monitor.is_primary,
321321
})
322322
.collect();
323323

0 commit comments

Comments
 (0)