31
31
error: nil ];
32
32
}
33
33
34
+ // Open a specific pane in System Preferences Security and Privacy.
35
+ void OpenPrefPane (const std::string &pane_string) {
36
+ NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
37
+ NSString *pref_string = [NSString
38
+ stringWithFormat:
39
+ @" x-apple.systempreferences:com.apple.preference.security?%s " ,
40
+ pane_string.c_str ()];
41
+ [workspace openURL: [NSURL URLWithString: pref_string]];
42
+ }
43
+
34
44
// Dummy value to pass into function parameter for ThreadSafeFunction.
35
45
Napi::Value NoOp (const Napi::CallbackInfo &info) {
36
46
return info.Env ().Undefined ();
@@ -491,10 +501,7 @@ bool HasOpenSystemPreferencesDialog() {
491
501
492
502
// Request Full Disk Access.
493
503
void AskForFullDiskAccess (const Napi::CallbackInfo &info) {
494
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
495
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
496
- @" security?Privacy_AllFiles" ;
497
- [workspace openURL: [NSURL URLWithString: pref_string]];
504
+ OpenPrefPane (" Privacy_AllFiles" );
498
505
}
499
506
500
507
// Request Camera access.
@@ -522,11 +529,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
522
529
tsfn.Release ();
523
530
}];
524
531
} else if (auth_status == kDenied ) {
525
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
526
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
527
- @" security?Privacy_Camera" ;
528
-
529
- [workspace openURL: [NSURL URLWithString: pref_string]];
532
+ OpenPrefPane (" Privacy_Camera" );
530
533
531
534
ts_fn.Release ();
532
535
deferred.Resolve (Napi::String::New (env, kDenied ));
@@ -568,11 +571,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
568
571
tsfn.Release ();
569
572
}];
570
573
} else if (auth_status == kDenied ) {
571
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
572
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
573
- @" security?Privacy_SpeechRecognition" ;
574
-
575
- [workspace openURL: [NSURL URLWithString: pref_string]];
574
+ OpenPrefPane (" Privacy_SpeechRecognition" );
576
575
577
576
ts_fn.Release ();
578
577
deferred.Resolve (Napi::String::New (env, kDenied ));
@@ -611,11 +610,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
611
610
tsfn.Release ();
612
611
}];
613
612
} else if (auth_status == kDenied ) {
614
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
615
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
616
- @" security?Privacy_Photos" ;
617
-
618
- [workspace openURL: [NSURL URLWithString: pref_string]];
613
+ OpenPrefPane (" Privacy_Photos" );
619
614
620
615
ts_fn.Release ();
621
616
deferred.Resolve (Napi::String::New (env, kDenied ));
@@ -656,11 +651,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
656
651
tsfn.Release ();
657
652
}];
658
653
} else if (auth_status == kDenied ) {
659
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
660
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
661
- @" security?Privacy_Microphone" ;
662
-
663
- [workspace openURL: [NSURL URLWithString: pref_string]];
654
+ OpenPrefPane (" Privacy_Microphone" );
664
655
665
656
ts_fn.Release ();
666
657
deferred.Resolve (Napi::String::New (env, kDenied ));
@@ -688,11 +679,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
688
679
IOHIDRequestAccess (kIOHIDRequestTypeListenEvent );
689
680
deferred.Resolve (Napi::String::New (env, kDenied ));
690
681
} else if (auth_status == kDenied ) {
691
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
692
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
693
- @" security?Privacy_ListenEvent" ;
694
-
695
- [workspace openURL: [NSURL URLWithString: pref_string]];
682
+ OpenPrefPane (" Privacy_ListenEvent" );
696
683
697
684
deferred.Resolve (Napi::String::New (env, kDenied ));
698
685
} else {
@@ -730,11 +717,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
730
717
tsfn.Release ();
731
718
}];
732
719
} else if (auth_status == kDenied ) {
733
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
734
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
735
- @" security?Privacy_Media" ;
736
-
737
- [workspace openURL: [NSURL URLWithString: pref_string]];
720
+ OpenPrefPane (" Privacy_Media" );
738
721
739
722
ts_fn.Release ();
740
723
deferred.Resolve (Napi::String::New (env, kDenied ));
@@ -768,11 +751,7 @@ void AskForScreenCaptureAccess(const Napi::CallbackInfo &info) {
768
751
CFRelease (stream);
769
752
} else {
770
753
if (!HasOpenSystemPreferencesDialog ()) {
771
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
772
- NSString *pref_string =
773
- @" x-apple.systempreferences:com.apple.preference."
774
- @" security?Privacy_ScreenCapture" ;
775
- [workspace openURL: [NSURL URLWithString: pref_string]];
754
+ OpenPrefPane (" Privacy_ScreenCapture" );
776
755
}
777
756
}
778
757
}
@@ -784,10 +763,7 @@ void AskForAccessibilityAccess(const Napi::CallbackInfo &info) {
784
763
bool trusted = AXIsProcessTrustedWithOptions ((CFDictionaryRef)options);
785
764
786
765
if (!trusted) {
787
- NSWorkspace *workspace = [[NSWorkspace alloc ] init ];
788
- NSString *pref_string = @" x-apple.systempreferences:com.apple.preference."
789
- @" security?Privacy_Accessibility" ;
790
- [workspace openURL: [NSURL URLWithString: pref_string]];
766
+ OpenPrefPane (" Privacy_Accessibility" );
791
767
}
792
768
}
793
769
0 commit comments