Skip to content

Commit

Permalink
try to fix issue #3261 with new api, but not sure if it works
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jul 10, 2023
1 parent 4e19777 commit a96eb23
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/platform/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
#include <Security/Authorization.h>
#include <Security/AuthorizationTags.h>

extern "C" bool CanUseNewApiForScreenCaptureCheck() {
#ifdef NO_InputMonitoringAuthStatus
return false;
#else
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
return version.majorVersion >= 11;
#endif
}

extern "C" bool IsCanScreenRecording(bool prompt) {
#ifdef NO_InputMonitoringAuthStatus
return false;
#else
bool res = CGPreflightScreenCaptureAccess();
if (!res && prompt) {
CGRequestScreenCaptureAccess();
}
return res;
#endif
}


// https://github.com/codebytere/node-mac-permissions/blob/main/permissions.mm

Expand Down
10 changes: 10 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern "C" {
static kAXTrustedCheckOptionPrompt: CFStringRef;
fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> BOOL;
fn InputMonitoringAuthStatus(_: BOOL) -> BOOL;
fn IsCanScreenRecording(_: BOOL) -> BOOL;
fn CanUseNewApiForScreenCaptureCheck() -> BOOL;
fn MacCheckAdminAuthorization() -> BOOL;
fn MacGetModeNum(display: u32, numModes: *mut u32) -> BOOL;
fn MacGetModes(
Expand Down Expand Up @@ -71,6 +73,14 @@ pub fn is_can_input_monitoring(prompt: bool) -> bool {
// https://stackoverflow.com/questions/56597221/detecting-screen-recording-settings-on-macos-catalina/
// remove just one app from all the permissions: tccutil reset All com.carriez.rustdesk
pub fn is_can_screen_recording(prompt: bool) -> bool {
// we got some report that we show no permission even after set it, so we try to use new api for screen recording check
// the new api is only available on macOS >= 10.15, but on stackoverflow, some people said it works on >= 10.16 (crash on 10.15),
// but also some said it has bug on 10.16, so we just use it on 11.0.
unsafe {
if CanUseNewApiForScreenCaptureCheck() == YES {
return IsCanScreenRecording(if prompt { YES } else { NO }) == YES;
}
}
let mut can_record_screen: bool = false;
unsafe {
let our_pid: i32 = std::process::id() as _;
Expand Down

0 comments on commit a96eb23

Please sign in to comment.