|
6 | 6 | #import <Contacts/Contacts.h> |
7 | 7 | #import <CoreLocation/CoreLocation.h> |
8 | 8 | #import <EventKit/EventKit.h> |
| 9 | +#import <Photos/Photos.h> |
9 | 10 | #import <Foundation/Foundation.h> |
10 | 11 | #import <pwd.h> |
11 | 12 |
|
12 | 13 | /***** HELPER FUNCTIONS *****/ |
13 | 14 |
|
14 | | -// Dummy value to pass into function parameter for ThreadSafeFunction |
| 15 | +// Dummy value to pass into function parameter for ThreadSafeFunction. |
15 | 16 | Napi::Value NoOp(const Napi::CallbackInfo &info) { |
16 | 17 | return info.Env().Undefined(); |
17 | 18 | } |
18 | 19 |
|
19 | | -// Returns the user's home folder path |
| 20 | +// Returns the user's home folder path. |
20 | 21 | NSString *GetUserHomeFolderPath() { |
21 | 22 | NSString *path; |
22 | 23 | BOOL isSandboxed = |
|
35 | 36 | } |
36 | 37 |
|
37 | 38 | // Returns a status indicating whether the user has authorized Contacts |
38 | | -// access |
| 39 | +// access. |
39 | 40 | std::string ContactAuthStatus() { |
40 | 41 | std::string auth_status = "not determined"; |
41 | 42 |
|
|
54 | 55 | } |
55 | 56 |
|
56 | 57 | // Returns a status indicating whether the user has authorized |
57 | | -// Calendar/Reminders access |
| 58 | +// Calendar/Reminders access. |
58 | 59 | std::string EventAuthStatus(const std::string &type) { |
59 | 60 | std::string auth_status = "not determined"; |
60 | 61 |
|
|
73 | 74 | return auth_status; |
74 | 75 | } |
75 | 76 |
|
76 | | -// Returns a status indicating whether the user has Full Disk Access |
| 77 | +// Returns a status indicating whether the user has Full Disk Access. |
77 | 78 | std::string FDAAuthStatus() { |
78 | 79 | std::string auth_status = "not determined"; |
79 | 80 | NSString *path; |
|
100 | 101 | } |
101 | 102 |
|
102 | 103 | // Returns a status indicating whether the user has authorized |
103 | | -// Screen Capture access |
| 104 | +// Screen Capture access. |
104 | 105 | std::string ScreenAuthStatus() { |
105 | 106 | std::string auth_status = "not determined"; |
106 | 107 | if (@available(macOS 10.15, *)) { |
|
147 | 148 | } |
148 | 149 |
|
149 | 150 | // Returns a status indicating whether the user has authorized |
150 | | -// Camera/Microphone access |
| 151 | +// Camera/Microphone access. |
151 | 152 | std::string MediaAuthStatus(const std::string &type) { |
152 | 153 | std::string auth_status = "not determined"; |
153 | 154 |
|
|
171 | 172 | } |
172 | 173 |
|
173 | 174 | // Returns a status indicating whether the user has authorized location |
174 | | -// access |
| 175 | +// access. |
175 | 176 | std::string LocationAuthStatus() { |
176 | 177 | std::string auth_status = "not determined"; |
177 | 178 |
|
|
187 | 188 | return auth_status; |
188 | 189 | } |
189 | 190 |
|
| 191 | +// Returns a status indicating whether or not the user has authorized Photos |
| 192 | +// access. |
| 193 | +std::string PhotosAuthStatus() { |
| 194 | + std::string auth_status = "not determined"; |
| 195 | + |
| 196 | + if (@available(macOS 10.13, *)) { |
| 197 | + PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; |
| 198 | + |
| 199 | + if (status == PHAuthorizationStatusAuthorized) |
| 200 | + auth_status = "authorized"; |
| 201 | + else if (status == PHAuthorizationStatusDenied) |
| 202 | + auth_status = "denied"; |
| 203 | + else if (status == PHAuthorizationStatusRestricted) |
| 204 | + auth_status = "restricted"; |
| 205 | + } else { |
| 206 | + auth_status = "authorized"; |
| 207 | + } |
| 208 | + |
| 209 | + return auth_status; |
| 210 | +} |
| 211 | + |
190 | 212 | /***** EXPORTED FUNCTIONS *****/ |
191 | 213 |
|
192 | | -// Returns the user's access consent status as a string |
| 214 | +// Returns the user's access consent status as a string. |
193 | 215 | Napi::Value GetAuthStatus(const Napi::CallbackInfo &info) { |
194 | 216 | Napi::Env env = info.Env(); |
195 | 217 | std::string auth_status; |
|
205 | 227 | auth_status = FDAAuthStatus(); |
206 | 228 | } else if (type == "microphone") { |
207 | 229 | auth_status = MediaAuthStatus("microphone"); |
| 230 | + } else if (type == "photos") { |
| 231 | + auth_status = PhotosAuthStatus(); |
208 | 232 | } else if (type == "camera") { |
209 | 233 | auth_status = MediaAuthStatus("camera"); |
210 | 234 | } else if (type == "accessibility") { |
|
218 | 242 | return Napi::Value::From(env, auth_status); |
219 | 243 | } |
220 | 244 |
|
221 | | -// Request access to the Contacts store. |
| 245 | +// Request Contacts access. |
222 | 246 | Napi::Promise AskForContactsAccess(const Napi::CallbackInfo &info) { |
223 | 247 | Napi::Env env = info.Env(); |
224 | 248 | Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env); |
|
245 | 269 | return deferred.Promise(); |
246 | 270 | } |
247 | 271 |
|
248 | | -// Request access to Calendar. |
| 272 | +// Request Calendar access. |
249 | 273 | Napi::Promise AskForCalendarAccess(const Napi::CallbackInfo &info) { |
250 | 274 | Napi::Env env = info.Env(); |
251 | 275 | Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env); |
|
268 | 292 | return deferred.Promise(); |
269 | 293 | } |
270 | 294 |
|
271 | | -// Request access to Reminders. |
| 295 | +// Request Reminders access. |
272 | 296 | Napi::Promise AskForRemindersAccess(const Napi::CallbackInfo &info) { |
273 | 297 | Napi::Env env = info.Env(); |
274 | 298 | Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env); |
@@ -300,7 +324,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) { |
300 | 324 | [workspace openURL:[NSURL URLWithString:pref_string]]; |
301 | 325 | } |
302 | 326 |
|
303 | | -// Request Camera Access. |
| 327 | +// Request Camera access. |
304 | 328 | Napi::Promise AskForCameraAccess(const Napi::CallbackInfo &info) { |
305 | 329 | Napi::Env env = info.Env(); |
306 | 330 | Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env); |
@@ -342,7 +366,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) { |
342 | 366 | return deferred.Promise(); |
343 | 367 | } |
344 | 368 |
|
345 | | -// Request Microphone Access. |
| 369 | +// Request Microphone access. |
346 | 370 | Napi::Promise AskForMicrophoneAccess(const Napi::CallbackInfo &info) { |
347 | 371 | Napi::Env env = info.Env(); |
348 | 372 | Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env); |
|
0 commit comments