device_query icon indicating copy to clipboard operation
device_query copied to clipboard

[macOS] Allow Safe Erroring

Open dcvz opened this issue 2 years ago • 3 comments

On macOS, the ApplicationServices framework is used to request access to the keyboard. At the moment the code asserts if that is not granted which will crash any app using this library.

This PR changes the behaviour to allow for safe erroring, creating new state returns an Option which allows the client to catch that error and do something about it without having to crash.

However, this is a breaking change to the API as users will now have to handle the Option being returned.. but overall I believe this is much safer.


On my version of macOS even though the prompt does come, it immediately returns false to the program.

dcvz avatar May 17 '23 10:05 dcvz

Hey thanks for the PR! I think this has a lot of good ideas in it and I'd be fine bumping the version since it's breaking. Lemme do some testing on other OSes and stuff and we'll get this pulled in.

ostrosco avatar May 18 '23 23:05 ostrosco

I'm so sorry that it's taken this long to revisit; things have been a bit nuts here.

I'd like to propose a few changes to this:

  1. I'd like to change the function names to try_new() so that way we don't need to break the API for this. I'd be open to revisiting breaking the API later but I feel like that would be the path of least resistance.
  2. I'd think these functions should return Result instead of Option. I'm not confident what the error type should be for this (maybe just a string?) but I think that communicates that this is a potential failure.

Let me know what you think and I sincerely apologize for the long turn around time on this.

ostrosco avatar Jun 19 '23 15:06 ostrosco

Noticed it late. The MR #74 adds a checked_new public API that returns Option<Self>.

dilawar avatar Jul 13 '23 10:07 dilawar