Skip to content

Modernized to modern Swifty style, features, and Swift version bump #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

mredig
Copy link

@mredig mredig commented Jun 14, 2025

Some of it was opinionated (like moving the constants organization so each type has its own file and nesting the constant types)

Some was modernizing the features (typed throws)

Some was restructuring away from enums where values aren't inherently limited in scope (as the underlying types are stringly typed and can apparently have new values added via the system), while also removing the need for string variant methods.

Additionally, it was all done with drop in compatibility in mind... (nested types now have a top level typealias marked as deprecated to keep the source of truth properly scoped, but not break existing code and enums are now structs with static properties matching their old cases.) The only thing that I can think of that would require any code editing would be if someone required exhausting switching over an enum that got changed to a struct, but that shouldn't be common, nor would I expect it would be a good idea with the possibility that values could exist outside those scopes.

Also, it should generally be compatible with Swift 6.1 (current as of this writing), but kAXTrustedCheckOptionPrompt causes compilation errors due to concurrency safety (Reference to var 'kAXTrustedCheckOptionPrompt' is not concurrency-safe because it involves shared mutable state). I cannot figure out how to either tell the compiler to ignore it or fix the issue. I created another PR (#46) where I replace it with a raw, inline string, but I don't know if that would be a good idea, so I'm just leaving this PR as Swift 5.10 since that has all the necessary modern features for my updates, but you could also choose the other one with the later Swift version (If you like my changes).

    /// Checks if the current process is a trusted accessibility client. If false, all APIs will
    /// throw errors.
    ///
    /// - parameter withPrompt: Whether to show the user a prompt if the process is untrusted. This
    ///                         happens asynchronously and does not affect the return value.
    open class func isProcessTrusted(withPrompt showPrompt: Bool = false) -> Bool {
        let options = [
            kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: showPrompt as CFBoolean
        ]
        return AXIsProcessTrustedWithOptions(options as CFDictionary)
    }

@mredig mredig marked this pull request as ready for review June 14, 2025 22:41
@mredig mredig mentioned this pull request Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant