Skip to content

Commit 51a2739

Browse files
feat: use CGPreFlightScreenCaptureAccess.CGRequestScreenCaptureAccess APIs on MacOS 11+ (#35)
1 parent e007364 commit 51a2739

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- name: Lint
2121
run: |
2222
npm install
23-
npm run lint
23+
npm run lint

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- name: npm install, build, and test
2121
run: |
2222
npm install
23-
npm test
23+
npm test

binding.gyp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"-framework CoreBluetooth",
2828
"-framework CoreFoundation",
2929
"-framework CoreLocation",
30+
"-framework CoreGraphics",
3031
"-framework Contacts",
3132
"-framework EventKit",
3233
"-framework Photos",
@@ -35,4 +36,4 @@
3536
]
3637
}
3738
}]
38-
}
39+
}

permissions.mm

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import <AppKit/AppKit.h>
66
#import <Contacts/Contacts.h>
77
#import <CoreBluetooth/CoreBluetooth.h>
8+
#import <CoreGraphics/CoreGraphics.h>
89
#import <CoreLocation/CoreLocation.h>
910
#import <EventKit/EventKit.h>
1011
#import <Foundation/Foundation.h>
@@ -202,7 +203,13 @@ bool HasOpenSystemPreferencesDialog() {
202203
// Screen Capture access.
203204
std::string ScreenAuthStatus() {
204205
std::string auth_status = kNotDetermined;
205-
if (@available(macOS 10.15, *)) {
206+
if (@available(macOS 11, *)) {
207+
if (CGPreflightScreenCaptureAccess()) {
208+
auth_status = kAuthorized;
209+
} else {
210+
auth_status = kDenied;
211+
}
212+
} else if (@available(macOS 10.15, *)) {
206213
auth_status = kDenied;
207214
NSRunningApplication *runningApplication =
208215
NSRunningApplication.currentApplication;
@@ -696,7 +703,9 @@ void AskForFullDiskAccess(const Napi::CallbackInfo &info) {
696703

697704
// Request Screen Capture Access.
698705
void AskForScreenCaptureAccess(const Napi::CallbackInfo &info) {
699-
if (@available(macOS 10.15, *)) {
706+
if (@available(macOS 11, *)) {
707+
CGRequestScreenCaptureAccess();
708+
} else if (@available(macOS 10.15, *)) {
700709
// Tries to create a capture stream. This is necessary to add the app back
701710
// to the list in sysprefs if the user previously denied.
702711
// https://stackoverflow.com/questions/56597221/detecting-screen-recording-settings-on-macos-catalina
@@ -765,4 +774,4 @@ void AskForAccessibilityAccess(const Napi::CallbackInfo &info) {
765774
return exports;
766775
}
767776

768-
NODE_API_MODULE(permissions, Init)
777+
NODE_API_MODULE(permissions, Init)

0 commit comments

Comments
 (0)