@@ -287,59 +287,71 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
287
287
Napi::Promise AskForCameraAccess (const Napi::CallbackInfo &info) {
288
288
Napi::Env env = info.Env ();
289
289
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New (env);
290
- Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New (env, Napi::Function::New (env, NoOp), " cameraAccessCallback" , 0 , 1 , [](Napi::Env) {});
290
+ Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New (
291
+ env, Napi::Function::New (env, NoOp), " cameraAccessCallback" , 0 , 1 ,
292
+ [](Napi::Env) {});
291
293
292
294
if (@available (macOS 10.14 , *)) {
293
295
std::string auth_status = MediaAuthStatus (" camera" );
294
296
295
297
if (auth_status == " not determined" ) {
296
- [AVCaptureDevice requestAccessForMediaType: AVMediaTypeVideo completionHandler: ^(BOOL granted) {
297
- auto callback = [=](Napi::Env env, Napi::Function js_cb, const char *granted) {
298
- deferred.Resolve (Napi::String::New (env, granted));
299
- };
300
-
301
- ts_fn.BlockingCall (granted ? " authorized" : " denied" , callback);
302
- }];
303
- } else if (auth_status == " denied" ){
298
+ [AVCaptureDevice
299
+ requestAccessForMediaType: AVMediaTypeVideo
300
+ completionHandler: ^(BOOL granted) {
301
+ auto callback = [=](Napi::Env env, Napi::Function js_cb,
302
+ const char *granted) {
303
+ deferred.Resolve (Napi::String::New (env, granted));
304
+ };
305
+
306
+ ts_fn.BlockingCall (granted ? " authorized" : " denied" ,
307
+ callback);
308
+ }];
309
+ } else if (auth_status == " denied" ) {
304
310
NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
305
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference.security?Privacy_Camera" ;
306
-
311
+ NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
312
+ @" security?Privacy_Camera" ;
313
+
307
314
[workspace openURL: [NSURL URLWithString: pref_string]];
308
315
309
316
deferred.Resolve (Napi::String::New (env, " denied" ));
310
317
} else {
311
318
deferred.Resolve (Napi::String::New (env, auth_status));
312
- }
319
+ }
313
320
} else {
314
321
deferred.Resolve (Napi::String::New (env, " authorized" ));
315
322
}
316
323
317
324
return deferred.Promise ();
318
325
}
319
326
320
-
321
-
322
327
// Request Microphone Access.
323
328
Napi::Promise AskForMicrophoneAccess (const Napi::CallbackInfo &info) {
324
329
Napi::Env env = info.Env ();
325
330
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New (env);
326
- Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New (env, Napi::Function::New (env, NoOp), " microphoneAccessCallback" , 0 , 1 , [](Napi::Env) {});
331
+ Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New (
332
+ env, Napi::Function::New (env, NoOp), " microphoneAccessCallback" , 0 , 1 ,
333
+ [](Napi::Env) {});
327
334
328
335
if (@available (macOS 10.14 , *)) {
329
336
std::string auth_status = MediaAuthStatus (" microphone" );
330
337
331
338
if (auth_status == " not determined" ) {
332
- [AVCaptureDevice requestAccessForMediaType: AVMediaTypeAudio completionHandler: ^(BOOL granted) {
333
- auto callback = [=](Napi::Env env, Napi::Function js_cb, const char *granted) {
334
- deferred.Resolve (Napi::String::New (env, granted));
335
- };
336
-
337
- ts_fn.BlockingCall (granted ? " authorized" : " denied" , callback);
338
- }];
339
+ [AVCaptureDevice
340
+ requestAccessForMediaType: AVMediaTypeAudio
341
+ completionHandler: ^(BOOL granted) {
342
+ auto callback = [=](Napi::Env env, Napi::Function js_cb,
343
+ const char *granted) {
344
+ deferred.Resolve (Napi::String::New (env, granted));
345
+ };
346
+
347
+ ts_fn.BlockingCall (granted ? " authorized" : " denied" ,
348
+ callback);
349
+ }];
339
350
} else if (auth_status == " denied" ) {
340
351
NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
341
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone" ;
342
-
352
+ NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
353
+ @" security?Privacy_Microphone" ;
354
+
343
355
[workspace openURL: [NSURL URLWithString: pref_string]];
344
356
345
357
deferred.Resolve (Napi::String::New (env, " denied" ));
@@ -388,9 +400,9 @@ void AskForAccessibilityAccess(const Napi::CallbackInfo &info) {
388
400
Napi::Function::New (env, AskForRemindersAccess));
389
401
exports.Set (Napi::String::New (env, " askForFullDiskAccess" ),
390
402
Napi::Function::New (env, AskForFullDiskAccess));
391
- exports.Set (Napi::String::New (env, " askForCameraAccess" ),
403
+ exports.Set (Napi::String::New (env, " askForCameraAccess" ),
392
404
Napi::Function::New (env, AskForCameraAccess));
393
- exports.Set (Napi::String::New (env, " askForMicrophoneAccess" ),
405
+ exports.Set (Napi::String::New (env, " askForMicrophoneAccess" ),
394
406
Napi::Function::New (env, AskForMicrophoneAccess));
395
407
exports.Set (Napi::String::New (env, " askForScreenCaptureAccess" ),
396
408
Napi::Function::New (env, AskForScreenCaptureAccess));
0 commit comments