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

Enable checking and prompting for required MacOS permissions to use this crate in an app #47

Merged
merged 2 commits into from
Jan 31, 2022

Conversation

Chris--B
Copy link
Contributor

@Chris--B Chris--B commented Jan 30, 2022

This change lays the ground work to expose "doesn't have permission to work on MacOS at all" through the API. As-is, it asserts and fails loudly until you give the app permissions.

Here's what a fresh MacOS build will look like to a new user as is:
image

This is much better than the current "silently don't do the crate's raison d'être", but not ideal. But the ground work here has been laid, so we just need to sort out what the API could look like! This relates to #44.

An important point to note: This depends on a crate that's razor thin, it just links to OS APIs, but is listed at version 0.0.1. This is less than ideal but it's pretty basic code that could be ported into this crate instead, if this is an issue.

I also made some minor changes reported by clippy and related things. I think these are only issues because clippy isn't run on MacOS as part of CI.

- Some lints and build failures fired on the doc comments
- I added more empty lines to make the samples less dense
- There's a Clippy lint that checks for a Default impl anytime a
struct has a
```
    pub fn new() -> Self
```
method. The default impl was only added to Linux, so I hoisted it
out into lib.rs to make it consistent across Windows and MacOS too
There's some design decisions to be made here, but the core works
@Chris--B Chris--B marked this pull request as ready for review January 30, 2022 01:38
@Chris--B Chris--B changed the title Minor doc formatting and clippy lints Enable checking and prompting for required MacOS permissions to use this crate in an app Jan 30, 2022
Comment on lines +140 to +156
/// Returns true if the Accessibility permissions necessary for this library to work are granted
/// to this process
///
/// If this returns false, the app can request them through the OS APIs, or the user can:
/// 1. open the MacOS system preferences
/// 2. go to Security -> Privacy
/// 3. scroll down to Accessibility and unlock it
/// 4. Add the app that is using device_query (such as your terminal) to the list
///
fn has_accessibility() -> bool {
use self::macos_accessibility_client::accessibility::*;
// Without prompting:
// application_is_trusted()

// With prompting:
application_is_trusted_with_prompt()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the change. Everything else is just touching up nits or making this work.

@ostrosco
Copy link
Owner

Thanks for this! I'm sure this will help the Mac users a lot (and cut down on filed issues when permissions aren't set correctly).

@ostrosco ostrosco merged commit 81c27cf into ostrosco:master Jan 31, 2022
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.

2 participants