24
24
const std::string kLimited {" limited" };
25
25
26
26
PHAccessLevel GetPHAccessLevel (const std::string &type)
27
- API_AVAILABLE(macosx(11.0 )) {
27
+ API_AVAILABLE(macosx(10.16 )) {
28
28
return type == " read-write" ? PHAccessLevelReadWrite : PHAccessLevelAddOnly;
29
29
}
30
30
@@ -37,7 +37,7 @@ PHAccessLevel GetPHAccessLevel(const std::string &type)
37
37
error: nil ];
38
38
}
39
39
40
- std::string StringFromPhotosStatus (PHAuthorizationStatus status) {
40
+ const std::string & StringFromPhotosStatus (PHAuthorizationStatus status) {
41
41
switch (status) {
42
42
case PHAuthorizationStatusAuthorized:
43
43
return kAuthorized ;
@@ -52,9 +52,9 @@ PHAccessLevel GetPHAccessLevel(const std::string &type)
52
52
}
53
53
}
54
54
55
- std::string
55
+ const std::string &
56
56
StringFromMusicLibraryStatus (SKCloudServiceAuthorizationStatus status)
57
- API_AVAILABLE(macosx(11 )) {
57
+ API_AVAILABLE(macosx(10.16 )) {
58
58
switch (status) {
59
59
case SKCloudServiceAuthorizationStatusAuthorized:
60
60
return kAuthorized ;
@@ -218,7 +218,7 @@ bool HasOpenSystemPreferencesDialog() {
218
218
// Returns a status indicating whether the user has authorized Apple Music
219
219
// Library access.
220
220
std::string MusicLibraryAuthStatus () {
221
- if (@available (macOS 11 , *)) {
221
+ if (@available (macOS 10.16 , *)) {
222
222
SKCloudServiceAuthorizationStatus status =
223
223
[SKCloudServiceController authorizationStatus ];
224
224
return StringFromMusicLibraryStatus (status);
@@ -275,7 +275,7 @@ bool HasOpenSystemPreferencesDialog() {
275
275
// Screen Capture access.
276
276
std::string ScreenAuthStatus () {
277
277
std::string auth_status = kNotDetermined ;
278
- if (@available (macOS 11 , *)) {
278
+ if (@available (macOS 10.16 , *)) {
279
279
if (CGPreflightScreenCaptureAccess ()) {
280
280
auth_status = kAuthorized ;
281
281
} else {
@@ -378,7 +378,7 @@ bool HasOpenSystemPreferencesDialog() {
378
378
std::string PhotosAuthStatus (const std::string &access_level) {
379
379
PHAuthorizationStatus status = PHAuthorizationStatusNotDetermined;
380
380
381
- if (@available (macOS 11 , *)) {
381
+ if (@available (macOS 10.16 , *)) {
382
382
PHAccessLevel level = GetPHAccessLevel (access_level);
383
383
status = [PHPhotoLibrary authorizationStatusForAccessLevel: level];
384
384
} else {
@@ -626,7 +626,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
626
626
627
627
if (auth_status == kNotDetermined ) {
628
628
__block Napi::ThreadSafeFunction tsfn = ts_fn;
629
- if (@available (macOS 11 , *)) {
629
+ if (@available (macOS 10.16 , *)) {
630
630
[PHPhotoLibrary
631
631
requestAuthorizationForAccessLevel: GetPHAccessLevel (access_level)
632
632
handler: ^(PHAuthorizationStatus status) {
@@ -637,21 +637,19 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
637
637
deferred.Resolve (Napi::String::New (
638
638
env, granted));
639
639
};
640
- std::string auth_result =
641
- StringFromPhotosStatus (status);
642
- tsfn. BlockingCall (auth_result .c_str (),
643
- callback);
640
+ tsfn. BlockingCall (
641
+ StringFromPhotosStatus (status)
642
+ .c_str (),
643
+ callback);
644
644
tsfn.Release ();
645
645
}];
646
646
} else {
647
- __block Napi::ThreadSafeFunction tsfn = ts_fn;
648
647
[PHPhotoLibrary requestAuthorization: ^(PHAuthorizationStatus status) {
649
648
auto callback = [=](Napi::Env env, Napi::Function js_cb,
650
649
const char *granted) {
651
650
deferred.Resolve (Napi::String::New (env, granted));
652
651
};
653
- std::string auth_result = StringFromPhotosStatus (status);
654
- tsfn.BlockingCall (auth_result.c_str (), callback);
652
+ tsfn.BlockingCall (StringFromPhotosStatus (status).c_str (), callback);
655
653
tsfn.Release ();
656
654
}];
657
655
}
@@ -740,7 +738,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
740
738
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New (
741
739
env, Napi::Function::New (env, NoOp), " musicLibraryCallback" , 0 , 1 );
742
740
743
- if (@available (macOS 11 , *)) {
741
+ if (@available (macOS 10.16 , *)) {
744
742
std::string auth_status = MusicLibraryAuthStatus ();
745
743
746
744
if (auth_status == kNotDetermined ) {
@@ -751,8 +749,8 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
751
749
const char *granted) {
752
750
deferred.Resolve (Napi::String::New (env, granted));
753
751
};
754
- std::string auth_result = StringFromMusicLibraryStatus (status);
755
- tsfn. BlockingCall (auth_result. c_str (), callback);
752
+ tsfn. BlockingCall ( StringFromMusicLibraryStatus (status). c_str (),
753
+ callback);
756
754
tsfn.Release ();
757
755
}];
758
756
} else if (auth_status == kDenied ) {
@@ -774,7 +772,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
774
772
775
773
// Request Screen Capture Access.
776
774
void AskForScreenCaptureAccess (const Napi::CallbackInfo &info) {
777
- if (@available (macOS 11 , *)) {
775
+ if (@available (macOS 10.16 , *)) {
778
776
CGRequestScreenCaptureAccess ();
779
777
} else if (@available (macOS 10.15 , *)) {
780
778
// Tries to create a capture stream. This is necessary to add the app back
0 commit comments