Skip to content

Commit c9ec480

Browse files
committed
feat: add speech recognition auth status check
1 parent b285bdf commit c9ec480

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ This native Node.js module allows you to manage an app's access to:
1919
* Accessibility
2020
* Location
2121
* Screen Capture
22+
* Speech Recognition
2223

2324
## API
2425

2526
## `permissions.getAuthStatus(type)`
2627

27-
* `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`, `screen`, or `reminders`.
28+
* `type` String - The type of system component to which you are requesting access. Can be one of `accessibility`, `calendar`, `camera`, `contacts`, `full-disk-access`, `speech-recognition`, `location`, `microphone`, `photos`, `screen`, or `reminders`.
2829

2930
Returns `String` - Can be one of `not determined`, `denied`, `authorized`, or `restricted`.
3031

@@ -41,6 +42,7 @@ Return Value Descriptions:
4142
* 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.
4243
* Access to `screen` will always return a status of `authorized` prior to macOS 10.15, as access to screen capture was unilaterally allowed until that version.
4344
* Access to `photos` will always return a status of `authorized` prior to macOS 10.13, as access to screen capture was unilaterally allowed until that version.
45+
* Access to `speech-recognition` will always return a status of `authorized` prior to macOS 10.15, as access to screen capture was unilaterally allowed until that version.
4446

4547
Example:
4648
```js
@@ -51,6 +53,7 @@ const types = [
5153
'full-disk-access',
5254
'camera',
5355
'photos',
56+
'speech-recognition',
5457
'microphone',
5558
'accessibility',
5659
'location'

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
2323
"xcode_settings": {
2424
"OTHER_CPLUSPLUSFLAGS": ["-std=c++14", "-stdlib=libc++"],
25-
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework CoreLocation -framework AppKit -framework Contacts -framework Photos -framework EventKit -framework AVFoundation"]
25+
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework CoreLocation -framework AppKit -framework Speech -framework Contacts -framework Photos -framework EventKit -framework AVFoundation"]
2626
}
2727
}]
2828
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function getAuthStatus(type) {
88
'full-disk-access',
99
'camera',
1010
'photos',
11+
'speech-recognition',
1112
'microphone',
1213
'accessibility',
1314
'location',

permissions.mm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import <EventKit/EventKit.h>
99
#import <Foundation/Foundation.h>
1010
#import <Photos/Photos.h>
11+
#import <Speech/Speech.h>
1112
#import <pwd.h>
1213

1314
/***** HELPER FUNCTIONS *****/
@@ -171,6 +172,28 @@
171172
return auth_status;
172173
}
173174

175+
// Returns a status indicating whether the user has authorized speech
176+
// recognition access.
177+
std::string SpeechRecognitionAuthStatus() {
178+
std::string auth_status = "not determined";
179+
180+
if (@available(macOS 10.15, *)) {
181+
SFSpeechRecognizerAuthorizationStatus status =
182+
[SFSpeechRecognizer authorizationStatus];
183+
184+
if (status == SFSpeechRecognizerAuthorizationStatusAuthorized)
185+
auth_status = "authorized";
186+
else if (status == SFSpeechRecognizerAuthorizationStatusDenied)
187+
auth_status = "denied";
188+
else if (status == SFSpeechRecognizerAuthorizationStatusRestricted)
189+
auth_status = "restricted";
190+
} else {
191+
auth_status = "authorized";
192+
}
193+
194+
return auth_status;
195+
}
196+
174197
// Returns a status indicating whether the user has authorized location
175198
// access.
176199
std::string LocationAuthStatus() {
@@ -229,6 +252,8 @@
229252
auth_status = MediaAuthStatus("microphone");
230253
} else if (type == "photos") {
231254
auth_status = PhotosAuthStatus();
255+
} else if (type == "speech-recognition") {
256+
auth_status = SpeechRecognitionAuthStatus();
232257
} else if (type == "camera") {
233258
auth_status = MediaAuthStatus("camera");
234259
} else if (type == "accessibility") {

test/module.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe('node-mac-permissions', () => {
1818
'reminders',
1919
'full-disk-access',
2020
'camera',
21+
'photos',
22+
'speech-recognition',
2123
'microphone',
2224
'accessibility',
2325
'location',

0 commit comments

Comments
 (0)