electron-util icon indicating copy to clipboard operation
electron-util copied to clipboard

Reading System Preferences [feature request]

Open alex-cory opened this issue 5 years ago • 8 comments

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 avatar Dec 23 '19 20:12 alex-cory

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

sindresorhus avatar Jan 02 '20 20:01 sindresorhus

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

alex-cory avatar Jan 06 '20 00:01 alex-cory

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);.

sindresorhus avatar Jan 06 '20 06:01 sindresorhus

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.

alex-cory avatar Jan 08 '20 01:01 alex-cory

@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());

sindresorhus avatar Jan 08 '20 03:01 sindresorhus

I can do my best to help implement this.

alex-cory avatar Jan 08 '20 07:01 alex-cory

@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 avatar Feb 03 '21 22:02 SinghManmohan

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

SinghManmohan avatar Feb 03 '21 23:02 SinghManmohan