node-mac-permissions
Advanced tools
Comparing version 1.0.1 to 1.2.0
@@ -10,3 +10,5 @@ const permissions = require('bindings')('permissions.node') | ||
'camera', | ||
'microphone' | ||
'microphone', | ||
'accessibility', | ||
'location' | ||
] | ||
@@ -19,8 +21,9 @@ | ||
return permissions.getAuthStatus.call(this, type) | ||
} | ||
} | ||
function askForMediaAccess(type, callback) { | ||
if (['microphone', 'camera'].includes(type)) { | ||
if (!['microphone', 'camera'].includes(type)) { | ||
throw new TypeError(`${type} must be either 'camera' or 'microphone'`) | ||
} | ||
if (typeof callback !== 'function') { | ||
@@ -27,0 +30,0 @@ throw new TypeError(`callback must be a function`) |
{ | ||
"name": "node-mac-permissions", | ||
"version": "1.0.1", | ||
"version": "1.2.0", | ||
"description": "A native node module to manage system permissions on macOS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/) | ||
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Actions Status](https://github.com/codebytere/node-mac-permissions/workflows/Test/badge.svg)](https://github.com/codebytere/node-mac-permissions/actions) | ||
# node-mac-permissions | ||
@@ -14,2 +17,6 @@ | ||
* Photos | ||
* Camera | ||
* Microphone | ||
* Accessibility | ||
* Location | ||
@@ -20,5 +27,5 @@ ## API | ||
* `type` String - The type of system component to which you are requesting access. Can be one of 'contacts', 'full-disk-access', 'photos', 'reminders', 'camera', 'microphone', or 'calendar'. | ||
* `type` String - The type of system component to which you are requesting access. Can be one of `accessibility`, `calendar`, `camera`, `contacts`, `full-disk-access`, `location`, `microphone`, `photos`, or `reminders`. | ||
Returns `String` - Can be one of 'not determined', 'denied', 'authorized', or 'restricted'. | ||
Returns `String` - Can be one of `not determined`, `denied`, `authorized`, or `restricted`. | ||
@@ -28,15 +35,35 @@ Checks the authorization status of the application to access `type` on macOS. | ||
Return Value Descriptions: | ||
* 'not determined' - The user has not yet made a choice regarding whether the application may access `type` data. | ||
* 'restricted' - The application is not authorized to access `type` data. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place. | ||
* 'denied' - The user explicitly denied access to `type` data for the application. | ||
* 'authorized' - The application is authorized to access `type` data. | ||
* `not determined` - The user has not yet made a choice regarding whether the application may access `type` data. | ||
* `restricted` - The application is not authorized to access `type` data. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place. | ||
* `denied` - The user explicitly denied access to `type` data for the application. | ||
* `authorized` - The application is authorized to access `type` data. | ||
**Notes:** | ||
* Access to 'contacts' will always return a status of 'Authorized' prior to macOS 10.11, as access to contacts was unilaterally allowed until that version. | ||
* Access to 'camera' and 'microphone' will always return a status of 'Authorized' prior to macOS 10.14, as access to contacts was unilaterally allowed until that version. | ||
* Access to `contacts` will always return a status of `authorized` prior to macOS 10.11, as access to contacts was unilaterally allowed until that version. | ||
* Access to `camera` and `microphone` will always return a status of `authorized` prior to macOS 10.14, as access to contacts was unilaterally allowed until that version. | ||
Example: | ||
```js | ||
const types = [ | ||
'contacts', | ||
'calendar', | ||
'reminders', | ||
'full-disk-access', | ||
'camera', | ||
'microphone', | ||
'accessibility', | ||
'location' | ||
] | ||
const statuses = ['not determined', 'denied', 'authorized', 'restricted'] | ||
for (const type of types) { | ||
const status = getAuthStatus(type) | ||
console.log(`Access to ${type} is ${status}`) | ||
} | ||
``` | ||
## `permissions.askForContactsAccess(callback)` | ||
* `callback` Function | ||
* `status` String - Whether or not the request succeeded or failed; can be 'authorized' or 'denied'. | ||
* `status` String - Whether or not the request succeeded or failed; can be `authorized` or `denied`. | ||
@@ -50,3 +77,3 @@ Your app’s `Info.plist` file must provide a value for the `NSContactsUsageDescription` key that explains to the user why your app is requesting Contacts access. | ||
**Note:** `status` will be called back as 'authorized' prior to macOS 10.11, as access to contacts was unilaterally allowed until that version. | ||
**Note:** `status` will be called back as `authorized` prior to macOS 10.11, as access to contacts was unilaterally allowed until that version. | ||
@@ -65,3 +92,3 @@ Example: | ||
* `callback` Function | ||
* `status` String - Whether or not the request succeeded or failed; can be 'authorized' or 'denied'. | ||
* `status` String - Whether or not the request succeeded or failed; can be `authorized` or `denied`. | ||
@@ -80,3 +107,3 @@ Example: | ||
* `callback` Function | ||
* `status` String - Whether or not the request succeeded or failed; can be 'authorized' or 'denied'. | ||
* `status` String - Whether or not the request succeeded or failed; can be `authorized` or `denied`. | ||
@@ -105,6 +132,6 @@ Example: | ||
* `type` String - The type of media to which you are requesting access. Can be 'microphone' or 'camera'. | ||
* `type` String - The type of media to which you are requesting access. Can be `microphone` or `camera`. | ||
* `callback` Function | ||
* `status` String - Whether or not the request succeeded or failed; can be 'authorized' or 'denied'. | ||
* `status` String - Whether or not the request succeeded or failed; can be `authorized` or `denied`. | ||
@@ -120,3 +147,3 @@ Your app must provide an explanation for its use of capture devices using the `NSCameraUsageDescription` or `NSMicrophoneUsageDescription` `Info.plist` keys; Calling this method or attempting to start a capture session without a usage description raises an exception. | ||
**Note:** `status` will be called back as 'authorized' prior to macOS 10.14 High Sierra, as access to the camera and microphone was unilaterally allowed until that version. | ||
**Note:** `status` will be called back as `authorized` prior to macOS 10.14 High Sierra, as access to the camera and microphone was unilaterally allowed until that version. | ||
@@ -123,0 +150,0 @@ Example: |
const { expect } = require('chai') | ||
const { | ||
getAuthStatus | ||
getAuthStatus, | ||
askForMediaAccess | ||
} = require('../index') | ||
@@ -21,3 +22,5 @@ | ||
'camera', | ||
'microphone' | ||
'microphone', | ||
'accessibility', | ||
'location' | ||
] | ||
@@ -32,2 +35,12 @@ | ||
}) | ||
}) | ||
describe('askForMediaAccess(type, callback)', () => { | ||
it ('throws on invalid media types', () => { | ||
expect(() => { | ||
askForMediaAccess('bad-type', (status) =>{ | ||
console.log(status) | ||
}) | ||
}).to.throw(/bad-type must be either 'camera' or 'microphone'/) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
20891
73
152