Skip to content
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

Alert developers on macOS when the app lacks permissions #44

Closed
Chris--B opened this issue Jan 15, 2022 · 1 comment
Closed

Alert developers on macOS when the app lacks permissions #44

Chris--B opened this issue Jan 15, 2022 · 1 comment

Comments

@Chris--B
Copy link
Contributor

Chris--B commented Jan 15, 2022

On macOS, accessibility permissions are required before this library will function at all. See here. This is already documented in the README, but to make it easier on developers using this crate it would be nice if a message could be logged when the app doesn't have permissions. The API could also do this check and expose it as a function somewhere, so that consumers of the crate can write it to their own popup or messaging for their users.

Here's the example from the README, modified to show an example API:

let device_state: DeviceState = match DeviceState::new() {
    Ok(device) => device,
    Err(DeviceError::InsufficientPermissions) => {
            message_box("Please enable Accessibility Permissions");
            return;
    },
    Err(e) => panic!("{}", e),
};

// The rest of the example is unchanged 
let mouse: MouseState = device_state.get_mouse();
println!("Current Mouse Coordinates: {:?}", mouse.coords);
let keys: Vec<Keycode> = device_state.get_keys();
println!("Is A pressed? {}", keys.contains(Keycode::A));

I have no idea if Apple's APIs will allow this or not, so this is just spit balling to show usage. Once we know this can work, we can iterate on what a useful API would actually look like.

This commit in dteoh/SlowQuitApps added a popup dialog and is probably a good starting place to figure out how to include this kind of check.

@Chris--B
Copy link
Contributor Author

Chris--B commented Jan 15, 2022

Reading more, I think this is actually a really short function to write:

BOOL hasAccessibility() {
    NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
    return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options);
}

https://developer.apple.com/documentation/applicationservices/1459186-axisprocesstrustedwithoptions
Just need to call into AXIsProcessTrustedWithOptions from Rust with an NSDictionary. 🤷‍♀️

This with an example that has a popup asking for the permission might be enough.

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

No branches or pull requests

2 participants