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

release-app fix operator find by id

Louis Beaumonte63be9a1ddc7
diff --git a/Cargo.lock b/Cargo.lock
index 182830b6b..2e0a17639 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5877,7 +5877,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "screenpipe-audio"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"anyhow",
"bytemuck",
@@ -5930,7 +5930,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"accessibility",
"accessibility-sys 0.2.0",
@@ -5972,7 +5972,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"anyhow",
"chrono",
@@ -5994,7 +5994,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"anyhow",
"chrono",
@@ -6012,7 +6012,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"anyhow",
"image",
@@ -6027,7 +6027,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"anyhow",
"axum",
@@ -6089,7 +6089,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.2.71"
+version = "0.2.72"
dependencies = [
"accessibility-sys 0.1.3",
"anyhow",
diff --git a/Cargo.toml b/Cargo.toml
index 7386475fb..e96b32fbc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ exclude = ["screenpipe-app-tauri/src-tauri"]
resolver = "2"
[workspace.package]
-version = "0.2.71"
+version = "0.2.72"
authors = ["louis030195 <[email protected]>"]
description = ""
repository = "https://github.com/mediar-ai/screenpipe"
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 69bce7227..cb48a83d2 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.43.4"
+version = "0.43.5"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-core/src/operator/platforms/macos.rs b/screenpipe-core/src/operator/platforms/macos.rs
index dbf93becc..0b249f3c9 100644
--- a/screenpipe-core/src/operator/platforms/macos.rs
+++ b/screenpipe-core/src/operator/platforms/macos.rs
@@ -18,8 +18,10 @@ use core_graphics::display::{CGPoint, CGSize};
use core_graphics::event::{CGEvent, CGEventFlags, CGKeyCode};
use core_graphics::event_source::CGEventSource;
use serde_json::{self, Value};
+use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::fmt;
+use std::hash::{Hash, Hasher};
use std::sync::Arc;
use tracing::{debug, trace};
@@ -589,8 +591,13 @@ impl AccessibilityEngine for MacOSEngine {
let collector = ElementFinderWithWindows::new(
&self.system_wide.0,
move |e| {
- // Use move to take ownership of id_owned
- e.identifier().unwrap_or(CFString::new("")).to_string() == id_owned
+ // Create temporary MacOSUIElement to generate stable ID
+ let element = MacOSUIElement {
+ element: ThreadSafeAXUIElement::new(e.clone()),
+ use_background_apps: false, // temporary value
+ activate_app: false, // temporary value
+ };
+ element.id().unwrap_or_default() == id_owned
},
None,
);
@@ -673,12 +680,51 @@ impl AccessibilityEngine for MacOSEngine {
Selector::Path(_) => Err(AutomationError::UnsupportedOperation(
"Path selector not implemented".to_string(),
)),
- _ => {
- // For more complex selectors, we'll mark as unimplemented for now
- Err(AutomationError::UnsupportedOperation(
- "Complex selector not implemented".to_string(),
- ))
+ Selector::Chain(selectors) => {
+ // For now, only support role -> id pattern
+ if selectors.len() != 2 {
+ return Err(AutomationError::UnsupportedOperation(
+ "Only role -> id chains are supported".to_string(),
+ ));
+ }
+
+ // Check if it's a role -> id pattern
+ if let (Selector::Role { role, name: _ }, Selector::Id(id)) =
+ (&selectors[0], &selectors[1])
+ {
+ debug!("Processing chain: role '{}' -> id '{}'", role, id);
+
+ // First find elements matching the role
+ let role_elements = self.find_elements(&selectors[0], root)?;
+ debug!(
+ "Found {} elements matching role '{}'",
+ role_elements.len(),
+ role
+ );
+
+ // Then find the one with matching id
+ for element in role_elements {
+ if let Some(element_id) = element.id() {
+ if element_id == *id {
+ debug!("Found matching element with id '{}'", id);
+ return Ok(element);
+ }
+ }
+ }
+
+ return Err(AutomationError::ElementNotFound(format!(
+ "No element found with role '{}' and id '{}'",
+ role, id
+ )));
+ } else {
+ return Err(AutomationError::UnsupportedOperation(
+ "Only role -> id chains are supported".to_string(),
+ ));
+ }
}
+ Selector::Filter(_) => Err(AutomationError::UnsupportedOperation(
+ "Filter selector not implemented".to_string(),
+ )),
}
}
@@ -1157,12 +1203,73 @@ impl MacOSUIElement {
Ok((key_code, flags))
}
+
+ fn generate_stable_id(&self) -> String {
+ let mut hasher = DefaultHasher::new();
+
+ // Collect stable attributes
+ let role = self
+ .element
+ .0
+ .role()
+ .map(|r| r.to_string())
+ .unwrap_or_default();
+ let title = self
+ .element
+ .0
+ .title()
+ .map(|t| t.to_string())
+ .unwrap_or_default();
+ let desc = self
+ .element
+ .0
+ .description()
+ .map(|d| d.to_string())
+ .unwrap_or_default();
+
+ // Get position if available (as integers to be more stable)
+ let (x, y, w, h) = self
+ .bounds()
+ .map(|(x, y, w, h)| {
+ (
+ x.round() as i32,
+ y.round() as i32,
+ w.round() as i32,
+ h.round() as i32,
+ )
+ })
+ .unwrap_or((0, 0, 0, 0));
+
+ // Hash combination of stable attributes
+ role.hash(&mut hasher);
+ title.hash(&mut hasher);
+ desc.hash(&mut hasher);
+ x.hash(&mut hasher);
+ y.hash(&mut hasher);
+ w.hash(&mut hasher);
+ h.hash(&mut hasher);
+
+ // Get parent info if available to make ID more unique
+ if let Ok(Some(parent)) = self.parent() {
+ if let Some(parent_role) = parent.attributes().label {
+ parent_role.hash(&mut hasher);
+ }
+ }
+
+ format!("ax_{:x}", hasher.finish())
+ }
}
impl UIElementImpl for MacOSUIElement {
fn object_id(&self) -> usize {
- // Use the pointer address of the inner AXUIElement as a unique ID
- self.element.0.as_ref() as *const _ as usize
+ // Convert stable string ID to usize
+ let stable_id = self.generate_stable_id();
+ let mut hasher = DefaultHasher::new();
+ stable_id.hash(&mut hasher);
+ let id = hasher.finish() as usize;
+ debug!("Stable ID: {:?}", stable_id);
+ debug!("Hash: {:?}", id);
+ id
}
fn as_any(&self) -> &dyn std::any::Any {
diff --git a/screenpipe-core/src/operator/tests.rs b/screenpipe-core/src/operator/tests.rs
index 76dec83b4..483758a4c 100644
--- a/screenpipe-core/src/operator/tests.rs
+++ b/screenpipe-core/src/operator/tests.rs
@@ -183,7 +183,7 @@ mod tests {
setup_tracing();
// Create a desktop automation instance
- let desktop = match Desktop::new(true, false) {
+ let desktop = match Desktop::new(true, true) {
Ok(d) => {
println!("Successfully created Desktop automation");
d
@@ -204,9 +204,53 @@ mod tests {
println!("App child #{}: {:?}", i, child.role());
}
- let input = app.locator("window").unwrap().first().unwrap_or_default();
- println!("found input: {:?}", input.is_some());
- println!("found input: {:?}", input.unwrap().text(10).unwrap());
+ let inputs = app
+ .locator("AXTextField")
+ .unwrap()
+ .all()
+ .unwrap_or_default();
+
+ for input in inputs.clone() {
+ println!("input: {:?}", input.id());
+ println!("input: {:?}", input.text(10).unwrap());
+ println!("input: {:?}", input.type_text("foo").unwrap());
+ println!("input: {:?}", input.role());
+ }
+
+ let specific_input = app
+ .locator("AXTextField")
+ .unwrap()
+ .first()
+ .unwrap()
+ .unwrap()
+ .locator(&*format!("#{}", inputs[0].id().unwrap()))
+ .unwrap()
+ .first()
+ .unwrap()
+ .unwrap();
+
+ println!("specific_input: {:?}", specific_input.text(10).unwrap());
+ println!(
+ "specific_input: {:?}",
+ specific_input.type_text("foobar").unwrap()
+ );
+ println!("specific_input: {:?}", specific_input.role());
+
+ let specific_input = app
+ .locator(&*format!("#{}", inputs[0].id().unwrap()))
+ .unwrap()
+ .first()
+ .unwrap()
+ .unwrap();
+
+ println!("specific_input: {:?}", specific_input.text(10).unwrap());
+ println!(
+ "specific_input: {:?}",
+ specific_input.type_text("foobarbaz").unwrap()
+ );
+ println!("specific_input: {:?}", specific_input.role());
+
+ let _ = Desktop::new(true, true).unwrap().application("cursor");
}
#[test]