From a96eb236c1c7b3d62fe8a819ba861f54921021e9 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 10 Jul 2023 17:31:04 +0800 Subject: [PATCH] try to fix issue #3261 with new api, but not sure if it works --- Cargo.lock | 2 +- src/platform/macos.mm | 21 +++++++++++++++++++++ src/platform/macos.rs | 10 ++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a46da69fa..8ce814328 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5146,7 +5146,7 @@ dependencies = [ [[package]] name = "rustdesk" -version = "1.2.0" +version = "1.2.1" dependencies = [ "android_logger", "arboard", diff --git a/src/platform/macos.mm b/src/platform/macos.mm index d40a56014..4a19973fc 100644 --- a/src/platform/macos.mm +++ b/src/platform/macos.mm @@ -4,6 +4,27 @@ #include #include +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 diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 3f480f839..fb61c7335 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -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( @@ -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 _;