|
30 | 30 | std::string ContactAuthStatus() { |
31 | 31 | std::string auth_status = "not determined"; |
32 | 32 |
|
33 | | - CNEntityType entityType = CNEntityTypeContacts; |
34 | | - CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:entityType]; |
| 33 | + CNEntityType entity_type = CNEntityTypeContacts; |
| 34 | + CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:entity_type]; |
35 | 35 |
|
36 | 36 | if (status == CNAuthorizationStatusAuthorized) |
37 | 37 | auth_status = "authorized"; |
|
44 | 44 | } |
45 | 45 |
|
46 | 46 | // Returns a status indicating whether or not the user has authorized Calendar/Reminders access |
47 | | -std::string EventAuthStatus(std::string type) { |
| 47 | +std::string EventAuthStatus(const std::string& type) { |
48 | 48 | std::string auth_status = "not determined"; |
49 | 49 |
|
50 | | - EKEntityType entityType = (type == "calendar") ? EKEntityTypeEvent : EKEntityTypeReminder; |
51 | | - EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:entityType]; |
| 50 | + EKEntityType entity_type = (type == "calendar") ? EKEntityTypeEvent : EKEntityTypeReminder; |
| 51 | + EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:entity_type]; |
52 | 52 |
|
53 | 53 | if (status == EKAuthorizationStatusAuthorized) |
54 | 54 | auth_status = "authorized"; |
|
60 | 60 | return auth_status; |
61 | 61 | } |
62 | 62 |
|
| 63 | +// Returns a status indicating whether or not the user has Full Disk Access |
63 | 64 | std::string FDAAuthStatus() { |
64 | 65 | std::string auth_status = "not determined"; |
65 | 66 | NSString *path; |
|
83 | 84 | return auth_status; |
84 | 85 | } |
85 | 86 |
|
| 87 | +// Returns a status indicating whether or not the user has authorized Camera/Microphone access |
| 88 | +std::string MediaAuthStatus(const std::string& type) { |
| 89 | + std::string auth_status = "not determined"; |
| 90 | + |
| 91 | + if (@available(macOS 10.14, *)) { |
| 92 | + AVMediaType media_type = (type == "microphone") ? AVMediaTypeAudio : AVMediaTypeVideo; |
| 93 | + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:media_type]; |
| 94 | + |
| 95 | + if (status == AVAuthorizationStatusAuthorized) |
| 96 | + auth_status = "authorized"; |
| 97 | + else if (status == AVAuthorizationStatusDenied) |
| 98 | + auth_status = "denied"; |
| 99 | + else if (status == AVAuthorizationStatusRestricted) |
| 100 | + auth_status = "restricted"; |
| 101 | + } else { |
| 102 | + auth_status = "authorized"; |
| 103 | + } |
| 104 | + |
| 105 | + return auth_status; |
| 106 | +} |
| 107 | + |
86 | 108 | /***** EXPORTED FUNCTIONS *****/ |
87 | 109 |
|
88 | 110 | // Returns the user's access consent status as a string |
|
99 | 121 | auth_status = EventAuthStatus("reminders"); |
100 | 122 | } else if (type == "full-disk-access") { |
101 | 123 | auth_status = FDAAuthStatus(); |
| 124 | + } else if (type == "microphone") { |
| 125 | + auth_status = MediaAuthStatus("microphone"); |
| 126 | + } else if (type == "camera") { |
| 127 | + auth_status = MediaAuthStatus("camera"); |
102 | 128 | } |
103 | 129 |
|
104 | 130 | return Napi::Value::From(env, auth_status); |
|
0 commit comments