node-mac-permissions
Advanced tools
Comparing version 2.1.4 to 2.2.0
11
index.js
@@ -25,5 +25,16 @@ const permissions = require('bindings')('permissions.node') | ||
function askForFoldersAccess(folder) { | ||
const validFolders = ['desktop', 'documents', 'downloads'] | ||
if (!validFolders.includes(folder)) { | ||
throw new TypeError(`${folder} is not a valid protected folder`) | ||
} | ||
return permissions.askForFoldersAccess.call(this, folder) | ||
} | ||
module.exports = { | ||
askForCalendarAccess: permissions.askForCalendarAccess, | ||
askForContactsAccess: permissions.askForContactsAccess, | ||
askForFoldersAccess, | ||
askForFullDiskAccess: permissions.askForFullDiskAccess, | ||
@@ -30,0 +41,0 @@ askForRemindersAccess: permissions.askForRemindersAccess, |
{ | ||
"name": "node-mac-permissions", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"description": "A native node module to manage system permissions on macOS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,3 @@ [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) | ||
* Speech Recognition | ||
* Protected Folders | ||
@@ -144,2 +145,33 @@ ## API | ||
## `permissions.askForFoldersAccess(folder)` | ||
* `type` String - The folder to which you are requesting access. Can be one of `desktop`, `documents`, or `downloads`. | ||
Returns `Promise<String>` - Whether or not the request succeeded or failed; can be `authorized` or `denied`. | ||
Example: | ||
```js | ||
const { askForFoldersAccess } = require('node-mac-permissions') | ||
askForFoldersAccess('desktop').then(status => { | ||
console.log(`Access to Desktop is ${status}`) | ||
}) | ||
``` | ||
``` | ||
<key>NSDesktopFolderUsageDescription</key> | ||
<string>Your reason for wanting to access the Desktop folder</string> | ||
``` | ||
``` | ||
<key>NSDocumentsFolderUsageDescription</key> | ||
<string>Your reason for wanting to access the Documents folder</string> | ||
``` | ||
``` | ||
<key>NSDownloadsFolderUsageDescription</key> | ||
<string>Your reason for wanting to access the Downloads folder</string> | ||
``` | ||
## `permissions.askForFullDiskAccess()` | ||
@@ -326,2 +358,11 @@ | ||
$ tccutil reset AddressBook | ||
# Reset Desktop folder access | ||
$ tccutil reset SystemPolicyDesktopFolder <bundleID> | ||
# Reset Documents folder access | ||
$ tccutil reset SystemPolicyDocumentsFolder <bundleID> | ||
# Reset Downloads folder access | ||
$ tccutil reset SystemPolicyDownloadsFolder <bundleID> | ||
``` |
const { expect } = require('chai') | ||
const { | ||
const { | ||
askForFoldersAccess, | ||
getAuthStatus, | ||
@@ -36,2 +37,10 @@ } = require('../index') | ||
}) | ||
describe('askForFoldersAccess()', () => { | ||
it('should throw on invalid types', () => { | ||
expect(() => { | ||
askForFoldersAccess('bad-type') | ||
}).to.throw(/bad-type is not a valid protected folder/) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45492
108
366