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

Querying and manually requesting permissions for Electron applications on Mac. #477

Closed
mushan0x0 opened this issue Feb 16, 2023 · 8 comments
Labels
feature New features

Comments

@mushan0x0
Copy link

Short overview

I want to trigger permission requests manually, so that I can better guide users to set permissions.

Detailed feature description

const Permission = {
  /**
   * Query whether the user has a certain permission
   * @param {string} permissionName - The name of the permission
   * @returns {boolean} - Whether the user has the permission
   */
  query(permissionName) {
    // Implement query logic
  },
  
  /**
   * Request a certain permission
   * @param {string} permissionName - The name of the permission
   * @returns {Promise<boolean>} - A Promise that resolves if the permission is granted, and rejects if the permission is not granted
   */
  request(permissionName) {
    // Implement request logic
  },
}
@s1hofmann s1hofmann added the feature New features label Feb 16, 2023
@s1hofmann
Copy link
Member

Hi @mushan0x0 👋

since this would be specific to macOS only I’d rather not add it to the core framework.
Instead, I’d suggest using https://github.com/nut-tree/node-mac-permissions directly.

Best regards

Simon

@mushan0x0
Copy link
Author

Thank @s1hofmann

But now whenever I run the program, it automatically jumps to the permission settings section. Can I control it manually?

@s1hofmann
Copy link
Member

Can I control it manually?

You mean explicitly disabling this behaviour? No.
The automated permissions check runs as soon as you call a function requiring e.g. accessibility and/or screen recording permissions.
An example would be keyboard.type

@mushan0x0
Copy link
Author

@s1hofmann

I used the keyboard.pressKey method in my program, but when I opened the program, this method was not called.
However, the system authorization interface was still displayed, which prevented me from guiding the user to the settings.
Normally, the authorization interface should be displayed only when this method is called?

@s1hofmann
Copy link
Member

I just noticed two methods requesting permissions that actually do not need them, I'll update that.

Regarding #476, have you removed the application from your permissions list yet?
It might be the case that you granted permissions once, but when you re-package your application, the permission check can't cope with it.

s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Feb 16, 2023
… from permissionCheck.js since these setters do not required any permissions
@mushan0x0
Copy link
Author

@s1hofmann

I used the keyboard.pressKey and keyboard.releaseKey APIs. It would be great if no authorization is needed for them, as this would greatly reduce the usage threshold. Thank you very much.

Regarding issue #476, it always exists on my computer. Even after removing and adding it again, it still has the same problem. However, when I installed it on another computer, there was no problem.

@s1hofmann s1hofmann added the wontfix This will not be worked on label Feb 16, 2023
@s1hofmann
Copy link
Member

These two methods definitely require accessibility permissions to work, so they can't be removed.

@s1hofmann s1hofmann removed the wontfix This will not be worked on label Feb 16, 2023
@s1hofmann
Copy link
Member

Hi @mushan0x0 👋

I just spent some more time on this topic since it kept circling in my head.
There’s indeed a bug that leads to the permissions dialog being shown eagerly.

I’ll work on that.
Sorry if I sounded harsh, I was at fault here.

Best regards

Simon

@s1hofmann s1hofmann reopened this Feb 16, 2023
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Feb 16, 2023
…heck results and only ask for permissions on actual function call by wrapping it in a HOF
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Feb 16, 2023
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Feb 16, 2023
#153)

* (nut-tree/nut.js#477) Removed both setMouseDelay and setKeyboardDelay from permissionCheck.js since these setters do not required any permissions

* (nut-tree/nut.js#477) Update permissionCheck.js to cache permission check results and only ask for permissions on actual function call by wrapping it in a HOF

* (nut-tree/nut.js#477) Re-require native bindings on error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New features
Projects
None yet
Development

No branches or pull requests

2 participants