Skip to content

Commit

Permalink
add FTS for app name and windows name and fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashashwini2003 committed Dec 15, 2024
1 parent 6d03f29 commit 7501312
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
20 changes: 10 additions & 10 deletions screenpipe-server/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ impl DatabaseManager {
AND (?3 IS NULL OR frames.timestamp <= ?3)
AND (?4 IS NULL OR LENGTH(ocr_text.text) >= ?4)
AND (?5 IS NULL OR LENGTH(ocr_text.text) <= ?5)
AND (?6 IS NULL OR ocr_text.app_name LIKE '%' || ?6 || '%' COLLATE NOCASE)
AND (?7 IS NULL OR ocr_text.window_name LIKE '%' || ?7 || '%' COLLATE NOCASE)
AND (?6 IS NULL OR ocr_text_fts MATCH 'app_name:' || quote(?6))
AND (?7 IS NULL OR ocr_text_fts MATCH 'window_name:' || quote(?7))
GROUP BY ocr_text.frame_id
ORDER BY frames.timestamp DESC
LIMIT ?8 OFFSET ?9
Expand Down Expand Up @@ -929,8 +929,8 @@ impl DatabaseManager {
WHERE {}
AND (?2 IS NULL OR frames.timestamp >= ?2)
AND (?3 IS NULL OR frames.timestamp <= ?3)
AND (?4 IS NULL OR ocr_text.app_name LIKE '%' || ?4 || '%')
AND (?5 IS NULL OR ocr_text.window_name LIKE '%' || ?5 || '%')
AND (?4 IS NULL OR ocr_text_fts MATCH 'app_name:' || quote(?4))
AND (?5 IS NULL OR ocr_text_fts MATCH 'window_name:' || quote(?5))
AND (?6 IS NULL OR LENGTH(ocr_text.text) >= ?6)
AND (?7 IS NULL OR LENGTH(ocr_text.text) <= ?7)
"#,
Expand Down Expand Up @@ -970,8 +970,8 @@ impl DatabaseManager {
WHERE {}
AND (?2 IS NULL OR ui_monitoring.timestamp >= ?2)
AND (?3 IS NULL OR ui_monitoring.timestamp <= ?3)
AND (?4 IS NULL OR ui_monitoring.app LIKE '%' || ?4 || '%')
AND (?5 IS NULL OR ui_monitoring.window LIKE '%' || ?5 || '%')
AND (?4 IS NULL OR ui_monitoring_fts MATCH 'app:' || quote(?4))
AND (?5 IS NULL OR ui_monitoring_fts MATCH 'window:' || quote(?5))
AND (?6 IS NULL OR LENGTH(ui_monitoring.text_output) >= ?6)
AND (?7 IS NULL OR LENGTH(ui_monitoring.text_output) <= ?7)
"#,
Expand All @@ -992,8 +992,8 @@ impl DatabaseManager {
WHERE {}
AND (?2 IS NULL OR frames.timestamp >= ?2)
AND (?3 IS NULL OR frames.timestamp <= ?3)
AND (?4 IS NULL OR ocr_text.app_name LIKE '%' || ?4 || '%')
AND (?5 IS NULL OR ocr_text.window_name LIKE '%' || ?5 || '%')
AND (?4 IS NULL OR ocr_text_fts MATCH 'app_name:' || quote(?4))
AND (?5 IS NULL OR ocr_text_fts MATCH 'window_name:' || quote(?5))
AND (?6 IS NULL OR LENGTH(ocr_text.text) >= ?6)
AND (?7 IS NULL OR LENGTH(ocr_text.text) <= ?7)
AND ocr_text.text != 'No text found'
Expand All @@ -1017,8 +1017,8 @@ impl DatabaseManager {
WHERE {}
AND (?2 IS NULL OR ui_monitoring.timestamp >= ?2)
AND (?3 IS NULL OR ui_monitoring.timestamp <= ?3)
AND (?4 IS NULL OR ui_monitoring.app LIKE '%' || ?4 || '%')
AND (?5 IS NULL OR ui_monitoring.window LIKE '%' || ?5 || '%')
AND (?4 IS NULL OR ui_monitoring_fts MATCH 'app:' || quote(?4))
AND (?5 IS NULL OR ui_monitoring_fts MATCH 'window:' || quote(?5))
AND (?6 IS NULL OR LENGTH(ui_monitoring.text_output) >= ?6)
AND (?7 IS NULL OR LENGTH(ui_monitoring.text_output) <= ?7)
AND ui_monitoring.text_output != ''
Expand Down
7 changes: 7 additions & 0 deletions screenpipe-server/tests/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ mod tests {
async fn setup_test_db() -> DatabaseManager {
let db = DatabaseManager::new("sqlite::memory:").await.unwrap();

// Apply migrations explicitly during test setup
sqlx::migrate!("../src/migrations")

Check failure on line 17 in screenpipe-server/tests/db.rs

View workflow job for this annotation

GitHub Actions / test-ubuntu

No such file or directory (os error 2)

Check failure on line 17 in screenpipe-server/tests/db.rs

View workflow job for this annotation

GitHub Actions / test-macos

No such file or directory (os error 2)
.run(&db.pool)
.await
.unwrap();
eprintln!("Current working directory: {:?}", std::env::current_dir().unwrap());

db
}

Expand Down
14 changes: 10 additions & 4 deletions screenpipe-vision/examples/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
use futures_util::{SinkExt, StreamExt};
use image::ImageEncoder;
use screenpipe_vision::{
continuous_capture, monitor::get_default_monitor, CaptureResult, OcrEngine,
continuous_capture, capture_screenshot_by_window::WindowFilters, monitor::get_default_monitor, CaptureResult, OcrEngine,
};
use serde::Serialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -83,10 +83,16 @@ async fn main() -> Result<()> {
let id = monitor.id();

tokio::spawn(async move {

let windows_filter = Arc::new(WindowFilters::new(
&cli.ignored_windows,
&cli.included_windows,
));


continuous_capture(
result_tx,
Duration::from_secs_f64(1.0 / cli.fps),
save_text_files,
// if apple use apple otherwise if windows use windows native otherwise use tesseract
if cfg!(target_os = "macos") {
OcrEngine::AppleNative
Expand All @@ -96,9 +102,9 @@ async fn main() -> Result<()> {
OcrEngine::Tesseract
},
id,
&cli.ignored_windows,
&cli.included_windows,
windows_filter,
vec![],
save_text_files,
)
.await
});
Expand Down
14 changes: 10 additions & 4 deletions screenpipe-vision/examples/window-filtering.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Result;
use clap::Parser;
use screenpipe_vision::{
continuous_capture, monitor::get_default_monitor, CaptureResult, OcrEngine,
continuous_capture,capture_screenshot_by_window::WindowFilters, monitor::get_default_monitor, CaptureResult, OcrEngine,
};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc::channel;
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};
Expand Down Expand Up @@ -37,10 +38,15 @@ async fn main() -> Result<()> {
let id = monitor.id();

tokio::spawn(async move {

let windows_filter = Arc::new(WindowFilters::new(
&cli.ignore,
&cli.include,
));

continuous_capture(
result_tx,
Duration::from_secs(1),
false,
// if apple use apple otherwise if windows use windows native otherwise use tesseract
if cfg!(target_os = "macos") {
OcrEngine::AppleNative
Expand All @@ -50,9 +56,9 @@ async fn main() -> Result<()> {
OcrEngine::Tesseract
},
id,
&cli.ignore,
&cli.include,
windows_filter,
vec![],
false,
)
.await
});
Expand Down
3 changes: 3 additions & 0 deletions screenpipe-vision/src/capture_screenshot_by_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use xcap_macoswin::{Monitor, Window, XCapError};
#[cfg(target_os = "linux")]
use xcap::{Monitor, Window, XCapError};

#[cfg(target_os = "windows")]
use xcap_win::{Monitor, Window, XCapError};

Check failure on line 17 in screenpipe-vision/src/capture_screenshot_by_window.rs

View workflow job for this annotation

GitHub Actions / test-windows

unresolved import `xcap_win`

Check failure on line 17 in screenpipe-vision/src/capture_screenshot_by_window.rs

View workflow job for this annotation

GitHub Actions / test-windows

unresolved import `xcap_win`

#[derive(Debug)]
enum CaptureError {
NoWindows,
Expand Down

0 comments on commit 7501312

Please sign in to comment.