macospermissionsuser-permissionscompose-multiplatform

How to make accessibility permissions persist?


I am developing an compose multiplatform app. It is packaged as by the compose gradle plugin into a .app bundle which I then move into my /Applications folder.

The app uses jnativehook to register global keyboard listeners. jnativehook requires accessibility permissions to hook into the native global events.

On first install, providing permissions works as expected:

  1. A pop-up prompt asks me to provide permissions.
  2. I click the button in the pop-up.
  3. I am brought to the Accessibility Permissions pane.
  4. I see a toggle for my app, which is OFF.
  5. I switch the toggle to ON.
  6. I restart the app
  7. The global event listeners now work as expected

The issue is that when I rebuild and reinstall the app, I am prompted to provide permissions again but it is no longer as easy:

Steps 1-3 are identical to the first-install case.

But step 4 in the reinstall case is different. Even though I was prompted to enable permissions, when reinstalling the toggle is already ON. Despite the toggle being on, the app behaves as if it is off. Also, the toggle no longer has any effect whatsoever. Switching it to OFF and restarting, or OFF, the ON, then restarting, or any similar attempt has no effect.

The only way I can proceed at this point is to do the following:

  1. hit the MINUS button in the permissions pane to delete the toggle for my app
  2. Restart my app
  3. Proceed from step 4 in the original steps for the first-time install

This workaround works reliably. However, it is not efficient or user friendly.

So, this is really a two-part question.

QUESTION 1: How can I avoid having to hit the MINUS button in the permissions pane each time I reinstall?

QUESTION 2: How can I avoid being prompted to re-enable the permissions on every app update alltogether? In other words, how can I make my accessibility permissions for an app persist even when I swap out the entire .app bundle during an update? Or is swapping out the entire .app bundle not the proper way to update?

Also note I asked this question on Ask Different and the question was closed as off-topic there. I was redirected to here.


Solution

  • The OS distinguishes new and old versions of your application by its code-signing ID. See this https://stackoverflow.com/a/58291165/233944 for details.

    If you code-sign your application, new builds will be recognized as the same application and privacy permissions will be retained.