adding input monitoring priviledge detect for mac

This commit is contained in:
rustdesk 2023-01-06 12:20:26 +08:00
parent 09435f43df
commit b048e5b280
6 changed files with 67 additions and 3 deletions

View File

@ -1,9 +1,16 @@
#[cfg(windows)]
fn build_windows() {
cc::Build::new().file("src/windows.cc").compile("windows");
let file = "src/platform/windows.cc";
cc::Build::new().file(file).compile("windows");
println!("cargo:rustc-link-lib=WtsApi32");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=windows.cc");
println!("cargo:rerun-if-changed={}", file);
}
#[cfg(target_os = "macos")]
fn build_mac() {
let file = "src/platform/macos.mm";
cc::Build::new().file(file).compile("macos");
println!("cargo:rerun-if-changed={}", file);
}
#[cfg(all(windows, feature = "inline"))]
@ -117,5 +124,8 @@ fn main() {
#[cfg(windows)]
build_windows();
#[cfg(target_os = "macos")]
build_mac();
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=framework=ApplicationServices");
println!("cargo:rerun-if-changed=build.rs");
}

View File

@ -1113,6 +1113,10 @@ pub fn main_is_can_screen_recording(prompt: bool) -> SyncReturn<bool> {
SyncReturn(is_can_screen_recording(prompt))
}
pub fn main_is_can_input_monitoring(prompt: bool) -> SyncReturn<bool> {
SyncReturn(is_can_input_monitoring(prompt))
}
pub fn main_is_share_rdp() -> SyncReturn<bool> {
SyncReturn(is_share_rdp())
}

34
src/platform/macos.mm Normal file
View File

@ -0,0 +1,34 @@
#import <AVFoundation/AVFoundation.h>
#import <AppKit/AppKit.h>
#import <IOKit/hidsystem/IOHIDLib.h>
extern "C" bool InputMonitoringAuthStatus(bool prompt) {
if (@available(macos 10.15, *)) {
IOHIDAccessType theType = IOHIDCheckAccess(kIOHIDRequestTypeListenEvent);
NSLog(@"IOHIDCheckAccess = %d", theType);
switch (theType) {
case kIOHIDAccessTypeGranted:
return true;
break;
case kIOHIDAccessTypeDenied: {
if (prompt) {
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
}
break;
}
case kIOHIDAccessTypeUnknown: {
if (prompt) {
bool result = IOHIDRequestAccess(kIOHIDRequestTypeListenEvent);
NSLog(@"IOHIDRequestAccess result = %d", result);
}
break;
}
default:
break;
}
} else {
return true;
}
return false;
}

View File

@ -32,6 +32,7 @@ extern "C" {
fn CGEventGetLocation(e: *const c_void) -> CGPoint;
static kAXTrustedCheckOptionPrompt: CFStringRef;
fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> BOOL;
fn InputMonitoringAuthStatus(_: BOOL) -> BOOL;
}
pub fn is_process_trusted(prompt: bool) -> bool {
@ -47,6 +48,13 @@ pub fn is_process_trusted(prompt: bool) -> bool {
}
}
pub fn is_can_input_monitoring(prompt: bool) -> bool {
unsafe {
let value = if prompt { YES } else { NO };
InputMonitoringAuthStatus(value) == YES
}
}
// macOS >= 10.15
// 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

View File

@ -582,6 +582,14 @@ pub fn is_installed_daemon(_prompt: bool) -> bool {
return true;
}
#[inline]
pub fn is_can_input_monitoring(_prompt: bool) -> bool {
#[cfg(target_os = "macos")]
return crate::platform::macos::is_can_input_monitoring(_prompt);
#[cfg(not(target_os = "macos"))]
return true;
}
#[inline]
pub fn get_error() -> String {
#[cfg(not(any(feature = "cli")))]