sindresorhus/electron-util

Reading System Preferences [feature request]

alex-cory opened this issue · 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.

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

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

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

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

I can do my best to help implement this.

@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

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