Skip to content

Commit

Permalink
monitor_ui_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutik7066 committed Feb 28, 2025
1 parent 47cf041 commit e255364
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion screenpipe-vision/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ windows = { version = "0.58", features = [
"Media_Ocr",
"Storage",
"Storage_Streams",
"Win32_System_Com"
"Win32_System_Com",
"Win32_UI_Accessibility",
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging"
Expand Down
25 changes: 25 additions & 0 deletions screenpipe-vision/src/run_ui_monitoring_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ fn build_text_output(element: &[ElementAttributes]) -> String {
fn measure_global_element_value_size(windows_state: &HashMap<HWND, WindowState>) -> usize {
windows_state.iter().map(|(_, ws)| ws.elements.len().sum())
}
fn monitor_ui_changes(automation: &IUIAutomation) -> Result<()> {
unsafe {
let root_element = automation.GetRootElement()?;
let condition = automation.CreateTrueCondition()?;

let event_handler = UIAutomationEventHandler::new(|_, sender, event_id| {
info!("UI Change detected! Event ID: {:?}", event_id);
if let Ok(automation) = get_ui_automation() {
if let Ok(element) = traverse_and_store_ui_elements(&automation, &sender) {
info!("New UI Element: {:?}", element);
}
}
Ok(())
});

automation.AddAutomationEventHandler(
UIA_StructureChangedEventId,
&root_element,
TreeScope_Subtree,
None,
&event_handler,
)?;
}
Ok(())
}

pub async fn run_ui() -> Result<()> {
Ok(())
Expand Down

0 comments on commit e255364

Please sign in to comment.