Skip to content

Commit

Permalink
✨ Small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jun 24, 2023
1 parent 851117b commit a7f6bfd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Loop/Helpers/AccessibilityAccessManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Defaults

class AccessibilityAccessManager {
@discardableResult
func checkAccessibilityAccess(ask: Bool) -> Bool {
func checkAccessibilityAccess(ask: Bool = false) -> Bool {
// Get current state for accessibility access
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: ask]
let status = AXIsProcessTrustedWithOptions(options)
Expand Down
18 changes: 8 additions & 10 deletions Loop/Helpers/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ struct WindowEngine {

private func getFocusedWindow(pid: pid_t) -> AXUIElement? {
let element = AXUIElementCreateApplication(pid)
if let window = element.copyAttributeValue(attribute: kAXFocusedWindowAttribute) {
// swiftlint:disable force_cast
return (window as! AXUIElement)
// swiftlint:enable force_cast
}
return nil
guard let window = element.copyAttributeValue(attribute: kAXFocusedWindowAttribute) else { return nil }
// swiftlint:disable force_cast
return (window as! AXUIElement)
// swiftlint:enable force_cast
}
private func getRole(element: AXUIElement) -> String? {
return element.copyAttributeValue(attribute: kAXRoleAttribute) as? String
Expand All @@ -76,9 +74,9 @@ struct WindowEngine {
}
private func getPosition(element: AXUIElement) -> CGPoint {
var point: CGPoint = .zero
guard let axValue = element.copyAttributeValue(attribute: kAXPositionAttribute) else { return point }
guard let value = element.copyAttributeValue(attribute: kAXPositionAttribute) else { return point }
// swiftlint:disable force_cast
AXValueGetValue(axValue as! AXValue, .cgPoint, &point)
AXValueGetValue(value as! AXValue, .cgPoint, &point) // Convert to CGPoint
// swiftlint:enable force_cast
return point
}
Expand All @@ -93,9 +91,9 @@ struct WindowEngine {
}
private func getSize(element: AXUIElement) -> CGSize {
var size: CGSize = .zero
guard let axValue = element.copyAttributeValue(attribute: kAXSizeAttribute) else { return size }
guard let value = element.copyAttributeValue(attribute: kAXSizeAttribute) else { return size }
// swiftlint:disable force_cast
AXValueGetValue(axValue as! AXValue, .cgSize, &size)
AXValueGetValue(value as! AXValue, .cgSize, &size) // Convert to CGSize
// swiftlint:enable force_cast
return size
}
Expand Down

0 comments on commit a7f6bfd

Please sign in to comment.