chore: format AXorcist

This commit is contained in:
Peter Steinberger 2025-11-19 20:19:19 +01:00
parent 7a999ba69e
commit 1bcf8a28c1
7 changed files with 19 additions and 16 deletions

View File

@ -17,18 +17,18 @@ public struct AXApp: Sendable {
self.init(app)
}
public var pid: pid_t { application.processIdentifier }
public var bundleIdentifier: String? { application.bundleIdentifier }
public var localizedName: String? { application.localizedName }
public var pid: pid_t { self.application.processIdentifier }
public var bundleIdentifier: String? { self.application.bundleIdentifier }
public var localizedName: String? { self.application.localizedName }
/// Windows exposed via AX for this application.
public func windows() -> [Element]? {
element.windows()
self.element.windows()
}
/// Focused window if available.
public func focusedWindow() -> Element? {
element.focusedWindow()
self.element.focusedWindow()
}
}
@ -42,12 +42,12 @@ public struct AXWindowHandle: Sendable {
self.element = element
}
public var title: String? { element.title() }
public var frame: CGRect? { element.frame() }
public var role: String? { element.role() }
public var title: String? { self.element.title() }
public var frame: CGRect? { self.element.frame() }
public var role: String? { self.element.role() }
/// CGWindowID for this AX window, if resolvable.
public var windowID: CGWindowID? {
AXWindowResolver().windowID(from: element)
AXWindowResolver().windowID(from: self.element)
}
}

View File

@ -80,7 +80,8 @@ public struct AXTimeoutWrapper {
} catch {
lastError = error
Logger(subsystem: "boo.peekaboo.axorcist", category: "AXTimeout")
.debug("AX operation failed (attempt \(attempt + 1)/\(self.maxRetries)): \(String(describing: error))")
.debug(
"AX operation failed (attempt \(attempt + 1)/\(self.maxRetries)): \(String(describing: error))")
if attempt < self.maxRetries - 1 {
try await Task.sleep(nanoseconds: UInt64(self.retryDelay * 1_000_000_000))
@ -129,7 +130,7 @@ public enum AXTimeoutError: Error, Sendable, CustomStringConvertible {
public var description: String {
switch self {
case let .operationTimedOut(duration):
return "Operation timed out after \(duration)s"
"Operation timed out after \(duration)s"
}
}
}

View File

@ -15,7 +15,8 @@ public enum AppLocator {
// Prefer frontmost app first (cheap).
if let front = NSWorkspace.shared.frontmostApplication,
Self.point(mouseLocation, isInsideWindowOf: front) {
Self.point(mouseLocation, isInsideWindowOf: front)
{
return front
}

View File

@ -126,6 +126,7 @@ public struct Attribute<T> {
public static var windows: Attribute<[AXUIElement]> {
Attribute<[AXUIElement]>(AXAttributeNames.kAXWindowsAttribute)
}
public static var sheets: Attribute<[AXUIElement]> {
Attribute<[AXUIElement]>(AXAttributeNames.kAXSheetsAttribute)
}

View File

@ -1,6 +1,6 @@
import Foundation
@testable import AXorcist
import Testing
@testable import AXorcist
@Suite("AXTimeoutHelper")
struct AXTimeoutHelperTests {

View File

@ -1,7 +1,7 @@
import AppKit
import CoreGraphics
@testable import AXorcist
import Testing
@testable import AXorcist
@Suite("AXWindowResolver")
struct AXWindowResolverTests {

View File

@ -1,7 +1,7 @@
import AppKit
import CoreGraphics
@testable import AXorcist
import Testing
@testable import AXorcist
@Suite("AppLocator")
struct AppLocatorTests {
@ -23,7 +23,7 @@ struct AppLocatorTests {
func fallbackToFrontmost() async throws {
guard let front = NSWorkspace.shared.frontmostApplication else { return }
// Pick an off-screen point unlikely to hit a window.
let offscreen = CGPoint(x: -10_000, y: -10_000)
let offscreen = CGPoint(x: -10000, y: -10000)
let app = AppLocator.app(at: offscreen)
#expect(app?.processIdentifier == front.processIdentifier)
}