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

Reading System Preferences [feature request] #25

Open
alex-cory opened this issue Dec 23, 2019 · 8 comments
Open

Reading System Preferences [feature request] #25

alex-cory opened this issue Dec 23, 2019 · 8 comments

Comments

@alex-cory
Copy link
Contributor

Currently there's openSystemPreferences, what if there was a readSystemPreferences or something similar. That way we could see what system preferences were currently set.

@alex-cory alex-cory changed the title Reading System Preferences Reading System Preferences [feature request] Dec 23, 2019
@sindresorhus
Copy link
Owner

Yeah, could be useful, but there's no "one way" to read the system preferences. What preferences specifically do you need?

@alex-cory
Copy link
Contributor Author

alex-cory commented Jan 6, 2020

So, I specifically need to display

  1. Accessibility has been enabled for the app (this might work for Accessibility)
  2. Full Disk Access has been enabled for the app
  3. Files and Folders has Documents, Downloads, and Desktop enabled for the app like the Backup and Sync from Google option below
    image

@sindresorhus
Copy link
Owner

sindresorhus commented Jan 6, 2020

It's not possible to read these from the System Preferences or defaults. It used to be possible to read the database of permissions directly, but this is no longer possible: https://apple.stackexchange.com/questions/362865/macos-list-apps-authorized-for-full-disk-access

Here's how we could do this:

  1. https://github.com/karaggeorge/macos-accessibility-permissions
  2. We can try reading a certain off-limits file: https://github.com/MacPaw/PermissionsKit/blob/43744ea29edb296e177d5890f9fe50d3f5476d52/PermissionsKit/Private/FullDiskAccess/MPFullDiskAccessAuthorizer.m#L68-L76
  3. We can check whether those directories are writable. fs.accessSync(path, fs.constants.W_OK);.

@alex-cory
Copy link
Contributor Author

alex-cory commented Jan 8, 2020

How do you think this api should look?

readSystemPreferences('Accessibility')
readSystemPreferences('FullDiskAccess')
readSystemPreferences('FilesAndFolders', 'Documents')
readSystemPreferences('FilesAndFolders', 'Downloads')
readSystemPreferences('FilesAndFolders', 'Desktop')

Just throwing ideas out there.

@sindresorhus
Copy link
Owner

@alex-cory They should be separate methods as they all can't behave exactly the same (some might need to be async, for example).

const {hasPrivacyPermission} = require('electron-util');

console.log(hasPrivacyPermission.fullDiskAccess());
console.log(hasPrivacyPermission.filesAndFoldersDesktop());

@alex-cory
Copy link
Contributor Author

I can do my best to help implement this.

@SinghManmohan
Copy link

SinghManmohan commented Feb 3, 2021

@sindresorhus : Can we open Notifications settings from System Preference directly?

const {openSystemPreferences} = require('electron-util');

openSystemPreferences('notifications');

Screen Shot 2021-02-03 at 2 55 47 PM

@SinghManmohan
Copy link

@sindresorhus : Please ignore.. i just tried a sample app and it works.. my bad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants