Skip to content

Commit faaa64b

Browse files
committed
fix: const issue and sdk number
1 parent 7f66b71 commit faaa64b

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

permissions.mm

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
const std::string kLimited{"limited"};
2525

2626
PHAccessLevel GetPHAccessLevel(const std::string &type)
27-
API_AVAILABLE(macosx(11.0)) {
27+
API_AVAILABLE(macosx(10.16)) {
2828
return type == "read-write" ? PHAccessLevelReadWrite : PHAccessLevelAddOnly;
2929
}
3030

@@ -37,7 +37,7 @@ PHAccessLevel GetPHAccessLevel(const std::string &type)
3737
error:nil];
3838
}
3939

40-
std::string StringFromPhotosStatus(PHAuthorizationStatus status) {
40+
const std::string &StringFromPhotosStatus(PHAuthorizationStatus status) {
4141
switch (status) {
4242
case PHAuthorizationStatusAuthorized:
4343
return kAuthorized;
@@ -52,9 +52,9 @@ PHAccessLevel GetPHAccessLevel(const std::string &type)
5252
}
5353
}
5454

55-
std::string
55+
const std::string &
5656
StringFromMusicLibraryStatus(SKCloudServiceAuthorizationStatus status)
57-
API_AVAILABLE(macosx(11)) {
57+
API_AVAILABLE(macosx(10.16)) {
5858
switch (status) {
5959
case SKCloudServiceAuthorizationStatusAuthorized:
6060
return kAuthorized;
@@ -218,7 +218,7 @@ bool HasOpenSystemPreferencesDialog() {
218218
// Returns a status indicating whether the user has authorized Apple Music
219219
// Library access.
220220
std::string MusicLibraryAuthStatus() {
221-
if (@available(macOS 11, *)) {
221+
if (@available(macOS 10.16, *)) {
222222
SKCloudServiceAuthorizationStatus status =
223223
[SKCloudServiceController authorizationStatus];
224224
return StringFromMusicLibraryStatus(status);
@@ -275,7 +275,7 @@ bool HasOpenSystemPreferencesDialog() {
275275
// Screen Capture access.
276276
std::string ScreenAuthStatus() {
277277
std::string auth_status = kNotDetermined;
278-
if (@available(macOS 11, *)) {
278+
if (@available(macOS 10.16, *)) {
279279
if (CGPreflightScreenCaptureAccess()) {
280280
auth_status = kAuthorized;
281281
} else {
@@ -378,7 +378,7 @@ bool HasOpenSystemPreferencesDialog() {
378378
std::string PhotosAuthStatus(const std::string &access_level) {
379379
PHAuthorizationStatus status = PHAuthorizationStatusNotDetermined;
380380

381-
if (@available(macOS 11, *)) {
381+
if (@available(macOS 10.16, *)) {
382382
PHAccessLevel level = GetPHAccessLevel(access_level);
383383
status = [PHPhotoLibrary authorizationStatusForAccessLevel:level];
384384
} else {
@@ -626,7 +626,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
626626

627627
if (auth_status == kNotDetermined) {
628628
__block Napi::ThreadSafeFunction tsfn = ts_fn;
629-
if (@available(macOS 11, *)) {
629+
if (@available(macOS 10.16, *)) {
630630
[PHPhotoLibrary
631631
requestAuthorizationForAccessLevel:GetPHAccessLevel(access_level)
632632
handler:^(PHAuthorizationStatus status) {
@@ -637,21 +637,19 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
637637
deferred.Resolve(Napi::String::New(
638638
env, granted));
639639
};
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);
644644
tsfn.Release();
645645
}];
646646
} else {
647-
__block Napi::ThreadSafeFunction tsfn = ts_fn;
648647
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
649648
auto callback = [=](Napi::Env env, Napi::Function js_cb,
650649
const char *granted) {
651650
deferred.Resolve(Napi::String::New(env, granted));
652651
};
653-
std::string auth_result = StringFromPhotosStatus(status);
654-
tsfn.BlockingCall(auth_result.c_str(), callback);
652+
tsfn.BlockingCall(StringFromPhotosStatus(status).c_str(), callback);
655653
tsfn.Release();
656654
}];
657655
}
@@ -740,7 +738,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
740738
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(
741739
env, Napi::Function::New(env, NoOp), "musicLibraryCallback", 0, 1);
742740

743-
if (@available(macOS 11, *)) {
741+
if (@available(macOS 10.16, *)) {
744742
std::string auth_status = MusicLibraryAuthStatus();
745743

746744
if (auth_status == kNotDetermined) {
@@ -751,8 +749,8 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
751749
const char *granted) {
752750
deferred.Resolve(Napi::String::New(env, granted));
753751
};
754-
std::string auth_result = StringFromMusicLibraryStatus(status);
755-
tsfn.BlockingCall(auth_result.c_str(), callback);
752+
tsfn.BlockingCall(StringFromMusicLibraryStatus(status).c_str(),
753+
callback);
756754
tsfn.Release();
757755
}];
758756
} else if (auth_status == kDenied) {
@@ -774,7 +772,7 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
774772

775773
// Request Screen Capture Access.
776774
void AskForScreenCaptureAccess(const Napi::CallbackInfo &info) {
777-
if (@available(macOS 11, *)) {
775+
if (@available(macOS 10.16, *)) {
778776
CGRequestScreenCaptureAccess();
779777
} else if (@available(macOS 10.15, *)) {
780778
// Tries to create a capture stream. This is necessary to add the app back

0 commit comments

Comments
 (0)