hs.ax: bridge attributeValue/setAttributeValue for JS-friendly AX values#38
hs.ax: bridge attributeValue/setAttributeValue for JS-friendly AX values#38
Conversation
Greptile SummaryThis PR adds Key concerns:
Confidence Score: 4/5Safe to merge after addressing the The bridging implementation is well-structured and logically correct. The shadow-variable issue is cosmetic. The Hammerspoon 2/Modules/hs.ax/HSAXElement.swift — specifically the unbridged Important Files Changed
|
| if let element = value as? UIElement { | ||
| return HSAXElement(element: element) |
There was a problem hiding this comment.
Shadow variable hides outer
element property
if let element = value as? UIElement introduces a local element that shadows the class-level let element: UIElement property. While this doesn't cause a runtime bug here, it makes the code harder to read and could introduce subtle errors if the body is ever extended to reference the instance property. A distinct name like uiElement would avoid the ambiguity.
| if let element = value as? UIElement { | |
| return HSAXElement(element: element) | |
| if let uiElement = value as? UIElement { | |
| return HSAXElement(element: uiElement) | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Hammerspoon 2/Modules/hs.ax/HSAXElement.swift
Line: 262-263
Comment:
**Shadow variable hides outer `element` property**
`if let element = value as? UIElement` introduces a local `element` that shadows the class-level `let element: UIElement` property. While this doesn't cause a runtime bug here, it makes the code harder to read and could introduce subtle errors if the body is ever extended to reference the instance property. A distinct name like `uiElement` would avoid the ambiguity.
```suggestion
if let uiElement = value as? UIElement {
return HSAXElement(element: uiElement)
}
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
This PR improves hs.ax attribute interoperability between AXSwift and JavaScript by making attributeValue and setAttributeValue symmetric and JS-friendly.
What changed
Updated HSAXElement.attributeValue(_:) to bridge AX/native values into JS-usable Hammerspoon bridge objects.
Updated HSAXElement.setAttributeValue(_:value:) with reverse bridging before writing attributes.
Why
Previously, some AX attribute values returned by attributeValue were difficult to use directly in JS due to native AX/CoreGraphics types not being bridged consistently. Also, setAttributeValue did not perform the inverse conversion, so read/write behavior was asymmetric.
This change makes the API behavior more predictable and practical in JS scripts.
Validation