Skip to content

Commit

Permalink
build: bump minumum macOS to 10.13
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed May 21, 2022
1 parent 1b2e2f0 commit 4f2d17c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 61 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ Return Value Descriptions:
**Notes:**
* Access to `bluetooth` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.
* Access to `camera` and `microphone` will always return a status of `authorized` prior to macOS 10.14, as the underlying API was not introduced until that version.
* Access to `contacts` will always return a status of `authorized` prior to macOS 10.11, as the underlying API was not introduced until that version.
* Access to `input-monitoring` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.
* Access to `music-library` will always return a status of `authorized` prior to macOS 11.0, as the underlying API was not introduced until that version.
* Access to `photos` will always return a status of `authorized` prior to macOS 10.13, as the underlying API was not introduced until that version.
* Access to `screen` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.
* Access to `speech-recognition` will always return a status of `authorized` prior to macOS 10.15, as the underlying API was not introduced until that version.

Expand Down Expand Up @@ -114,8 +112,6 @@ Your app’s `Info.plist` file must provide a value for the `NSContactsUsageDesc
<string>Your reason for wanting to access the Contact store</string>
```

**Note:** `status` will be resolved back as `authorized` prior to macOS 10.11, as the underlying API was not introduced until that version.

Example:
```js
const { askForContactsAccess } = require('node-mac-permissions')
Expand Down Expand Up @@ -350,10 +346,6 @@ Your app must provide an explanation for its use of the photo library using the
<string>Your reason for wanting to access Photos</string>
```

**Note:**

- `status` will be resolved back as `authorized` prior to macOS 10.13, as the underlying API was not introduced until that version.

Example:

```js
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET": "10.10",
"MACOSX_DEPLOYMENT_TARGET": "10.13",
"SYSTEM_VERSION_COMPAT": 1,
"OTHER_CPLUSPLUSFLAGS": ["-std=c++14", "-stdlib=libc++"],
"OTHER_LDFLAGS": [
Expand Down
91 changes: 39 additions & 52 deletions permissions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,15 @@ bool HasOpenSystemPreferencesDialog() {
// Returns a status indicating whether or not the user has authorized Photos
// access.
std::string PhotosAuthStatus() {
if (@available(macOS 10.13, *)) {
switch ([PHPhotoLibrary authorizationStatus]) {
case PHAuthorizationStatusAuthorized:
return kAuthorized;
case PHAuthorizationStatusDenied:
return kDenied;
case PHAuthorizationStatusRestricted:
return kRestricted;
default:
return kNotDetermined;
}
switch ([PHPhotoLibrary authorizationStatus]) {
case PHAuthorizationStatusAuthorized:
return kAuthorized;
case PHAuthorizationStatusDenied:
return kDenied;
case PHAuthorizationStatusRestricted:
return kRestricted;
default:
return kNotDetermined;
}

return kAuthorized;
Expand Down Expand Up @@ -431,23 +429,18 @@ bool HasOpenSystemPreferencesDialog() {
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(
env, Napi::Function::New(env, NoOp), "contactsCallback", 0, 1);

if (@available(macOS 10.11, *)) {
__block Napi::ThreadSafeFunction tsfn = ts_fn;
CNContactStore *store = [CNContactStore new];
[store requestAccessForEntityType:CNEntityTypeContacts
completionHandler:^(BOOL granted, NSError *error) {
auto callback = [=](Napi::Env env, Napi::Function js_cb,
const char *granted) {
deferred.Resolve(Napi::String::New(env, granted));
};
tsfn.BlockingCall(granted ? "authorized" : "denied",
callback);
tsfn.Release();
}];
} else {
ts_fn.Release();
deferred.Resolve(Napi::String::New(env, kAuthorized));
}
__block Napi::ThreadSafeFunction tsfn = ts_fn;
CNContactStore *store = [CNContactStore new];
[store
requestAccessForEntityType:CNEntityTypeContacts
completionHandler:^(BOOL granted, NSError *error) {
auto callback = [=](Napi::Env env, Napi::Function js_cb,
const char *granted) {
deferred.Resolve(Napi::String::New(env, granted));
};
tsfn.BlockingCall(granted ? "authorized" : "denied", callback);
tsfn.Release();
}];

return deferred.Promise();
}
Expand Down Expand Up @@ -594,33 +587,27 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
Napi::ThreadSafeFunction ts_fn = Napi::ThreadSafeFunction::New(
env, Napi::Function::New(env, NoOp), "photosCallback", 0, 1);

if (@available(macOS 10.13, *)) {
std::string auth_status = PhotosAuthStatus();

if (auth_status == kNotDetermined) {
__block Napi::ThreadSafeFunction tsfn = ts_fn;
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
auto callback = [=](Napi::Env env, Napi::Function js_cb,
const char *granted) {
deferred.Resolve(Napi::String::New(env, granted));
};
tsfn.BlockingCall(
status == PHAuthorizationStatusAuthorized ? "authorized" : "denied",
callback);
tsfn.Release();
}];
} else if (auth_status == kDenied) {
OpenPrefPane("Privacy_Photos");
std::string auth_status = PhotosAuthStatus();
if (auth_status == kNotDetermined) {
__block Napi::ThreadSafeFunction tsfn = ts_fn;
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
auto callback = [=](Napi::Env env, Napi::Function js_cb,
const char *granted) {
deferred.Resolve(Napi::String::New(env, granted));
};
tsfn.BlockingCall(status == PHAuthorizationStatusAuthorized ? "authorized"
: "denied",
callback);
tsfn.Release();
}];
} else if (auth_status == kDenied) {
OpenPrefPane("Privacy_Photos");

ts_fn.Release();
deferred.Resolve(Napi::String::New(env, kDenied));
} else {
ts_fn.Release();
deferred.Resolve(Napi::String::New(env, auth_status));
}
ts_fn.Release();
deferred.Resolve(Napi::String::New(env, kDenied));
} else {
ts_fn.Release();
deferred.Resolve(Napi::String::New(env, kAuthorized));
deferred.Resolve(Napi::String::New(env, auth_status));
}

return deferred.Promise();
Expand Down

0 comments on commit 4f2d17c

Please sign in to comment.