hands test 2
This commit is contained in:
@@ -238,26 +238,23 @@ func axTreeTool(_ args: [String: Any]) async throws -> [Content] {
|
||||
return [.text(try axTree(w, RefSource(pid: info.pid, window: id), treeOptions(args, origin: info.frame.origin)))]
|
||||
}
|
||||
|
||||
func windowText(_ root: AXUIElement, contains needle: String) throws -> Bool {
|
||||
func windowMatches(_ root: AXUIElement, _ needle: String) throws -> Int {
|
||||
let n = needle.lowercased()
|
||||
var visits = 0
|
||||
func walk(_ e: AXUIElement) throws -> Bool {
|
||||
var count = 0
|
||||
func walk(_ e: AXUIElement) throws {
|
||||
visits += 1
|
||||
if visits > maxVisits {
|
||||
return false
|
||||
return
|
||||
}
|
||||
_ = try axRole(e)
|
||||
for name in [kAXTitleAttribute, kAXDescriptionAttribute, kAXValueAttribute] {
|
||||
if text(e, name).lowercased().contains(n) {
|
||||
return true
|
||||
}
|
||||
if [kAXTitleAttribute, kAXDescriptionAttribute, kAXValueAttribute].contains(where: { text(e, $0).lowercased().contains(n) }) {
|
||||
count += 1
|
||||
}
|
||||
for c in children(e) {
|
||||
if try walk(c) {
|
||||
return true
|
||||
}
|
||||
try walk(c)
|
||||
}
|
||||
return false
|
||||
}
|
||||
return try walk(root)
|
||||
try walk(root)
|
||||
return count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user