Skip to content

Commit 6e93e4c

Browse files
committed
fix #1
1 parent 4875d8e commit 6e93e4c

File tree

8 files changed

+61
-27
lines changed

8 files changed

+61
-27
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ __pycache__
1313
*.pyd
1414
*.pyw
1515
*.pyz
16-
16+
*.egg-info
17+
build/
18+
dist/

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "terminator"
3-
version = "0.1.0"
3+
version = "0.1.3"
44
edition = "2024"
55

66
[dependencies]

examples/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/server.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,6 @@ struct AttributesResponse {
147147
id: Option<String>,
148148
}
149149

150-
impl AttributesResponse {
151-
fn from_element(element: &UIElement) -> Self {
152-
let attrs = element.attributes();
153-
Self {
154-
role: attrs.role,
155-
label: attrs.label,
156-
value: attrs.value,
157-
description: attrs.description,
158-
properties: attrs.properties,
159-
id: element.id(),
160-
}
161-
}
162-
}
163150

164151
// Response structure for element bounds
165152
#[derive(Serialize)]

python-sdk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "desktop-use"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
authors = [
99
{ name="mediar-ai", email="louis@mediar.ai" },
1010
]

src/platforms/windows.rs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,41 @@ impl AccessibilityEngine for WindowsEngine {
268268
"`Filter` selector not supported".to_string(),
269269
));
270270
}
271-
Selector::Chain(_selectors) => {
272-
return Err(AutomationError::UnsupportedOperation(
273-
"`selectors` selector not supported".to_string(),
274-
));
271+
Selector::Chain(selectors) => {
272+
if selectors.is_empty() {
273+
return Err(AutomationError::InvalidArgument(
274+
"Selector chain cannot be empty".to_string(),
275+
));
276+
}
277+
278+
// Find the parent element based on all selectors except the last one.
279+
let mut current_element_root = root.cloned();
280+
if selectors.len() > 1 {
281+
for selector in &selectors[..selectors.len() - 1] {
282+
// Use find_element to traverse the chain up to the parent
283+
let found_parent = self.find_element(selector, current_element_root.as_ref())?;
284+
current_element_root = Some(found_parent);
285+
}
286+
}
287+
288+
// Use the last selector to find all matching elements within the final parent.
289+
if let Some(last_selector) = selectors.last() {
290+
// Call find_elements with the last selector and the found parent
291+
return self.find_elements(last_selector, current_element_root.as_ref());
292+
} else {
293+
// Should not happen due to is_empty check, but handle defensively.
294+
// If there's only one selector, find_elements is called directly.
295+
// This branch essentially handles the case of a single-selector chain,
296+
// which shouldn't occur if selectors.len() > 1 condition is met above.
297+
// If len is 1, the last_selector will be the only selector.
298+
// Let's simplify: if len == 1, the loop is skipped, and we directly call find_elements.
299+
// If len > 1, we find the parent and then call find_elements.
300+
// The case selectors.last() is always Some here because of the is_empty check.
301+
// Therefore, this else branch is unreachable. We can remove it or log an error.
302+
// Let's return an empty vec for safety, though it indicates a logic issue if reached.
303+
debug!("Unreachable code reached in find_elements Selector::Chain");
304+
return Ok(Vec::new());
305+
}
275306
}
276307
};
277308

@@ -426,10 +457,24 @@ impl AccessibilityEngine for WindowsEngine {
426457
"`Filter` selector not supported".to_string(),
427458
));
428459
}
429-
Selector::Chain(_selectors) => {
430-
return Err(AutomationError::UnsupportedOperation(
431-
"`selectors` selector not supported".to_string(),
432-
));
460+
Selector::Chain(selectors) => {
461+
if selectors.is_empty() {
462+
return Err(AutomationError::InvalidArgument(
463+
"Selector chain cannot be empty".to_string(),
464+
));
465+
}
466+
467+
// Recursively find the element by traversing the chain.
468+
let mut current_element = root.cloned();
469+
for selector in selectors {
470+
let found_element = self.find_element(selector, current_element.as_ref())?;
471+
current_element = Some(found_element);
472+
}
473+
474+
// Return the final single element found after the full chain traversal.
475+
return current_element.ok_or_else(|| {
476+
AutomationError::ElementNotFound("Element not found after traversing chain".to_string())
477+
});
433478
}
434479
}
435480
}

ts-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "desktop-use",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"scripts": {

0 commit comments

Comments
 (0)