Open stefansundin opened 1 year ago
Not a fix but a workaround would be to use Electron's systemPreferences.isTrustedAccessibilityClient()
to have more control over showing the dialog, and then only do require("uiohook-napi")
once you know the permissions are already granted. This approach has other advantages too since it lets you warn the user with a custom message before seeing the scary ambiguously-worded dialog, and also avoids the occasional issue of needing to restart the app before the perms take effect.
PRs welcome, I don't own Mac.
Hello, thanks for the package.
It works great except for one condition when it is used together with Electron (v21.0.0 tested). On macOS, if the user has not granted the application the Accessibility permission then the application crashes when you call
uIOhook.start()
.I created an Electron Fiddle to make it easy for you to reproduce: https://gist.github.com/stefansundin/937b9b20b28d58bc4d3ff05157d412c5
I included the full crash log in the gist above (scroll to the bottom), but here's the important part:
If you run the application from the terminal then it is the terminal app's permission that takes effect. So if you've already given it accessibility permissions then you may have to revoke that in System Preferences -> Security & Privacy to trigger the crash.
Before the crash this is printed:
The prompt to grant accessibility permissions is shown as expected (see screenshot below), followed immediately by the crash. When run through Electron Fiddle the macOS crash reporter isn't shown.
The crash is happening on this line: https://github.com/SnosMe/uiohook-napi/blob/63745a540828de230392eee3e6cf85d8a4d09e13/src/lib/uiohook_worker.c#L179
I tried commenting that out and it prevents the crash, but of course there may be a memory leak created in that case.
Would love to hear if you have any ideas on how to safely address this problem. Thank you!
Versions: uiohook-napi v1.5.0, Electron v21.0.0, node.js v16.17.0