adding input monitoring priviledge detect for mac
This commit is contained in:
parent
09435f43df
commit
b048e5b280
16
build.rs
16
build.rs
@ -1,9 +1,16 @@
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn build_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:rustc-link-lib=WtsApi32");
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed={}", file);
|
||||||
println!("cargo:rerun-if-changed=windows.cc");
|
}
|
||||||
|
|
||||||
|
#[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"))]
|
#[cfg(all(windows, feature = "inline"))]
|
||||||
@ -117,5 +124,8 @@ fn main() {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
build_windows();
|
build_windows();
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
build_mac();
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
println!("cargo:rustc-link-lib=framework=ApplicationServices");
|
println!("cargo:rustc-link-lib=framework=ApplicationServices");
|
||||||
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
}
|
}
|
||||||
|
@ -1113,6 +1113,10 @@ pub fn main_is_can_screen_recording(prompt: bool) -> SyncReturn<bool> {
|
|||||||
SyncReturn(is_can_screen_recording(prompt))
|
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> {
|
pub fn main_is_share_rdp() -> SyncReturn<bool> {
|
||||||
SyncReturn(is_share_rdp())
|
SyncReturn(is_share_rdp())
|
||||||
}
|
}
|
||||||
|
34
src/platform/macos.mm
Normal file
34
src/platform/macos.mm
Normal 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;
|
||||||
|
}
|
@ -32,6 +32,7 @@ extern "C" {
|
|||||||
fn CGEventGetLocation(e: *const c_void) -> CGPoint;
|
fn CGEventGetLocation(e: *const c_void) -> CGPoint;
|
||||||
static kAXTrustedCheckOptionPrompt: CFStringRef;
|
static kAXTrustedCheckOptionPrompt: CFStringRef;
|
||||||
fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> BOOL;
|
fn AXIsProcessTrustedWithOptions(options: CFDictionaryRef) -> BOOL;
|
||||||
|
fn InputMonitoringAuthStatus(_: BOOL) -> BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_process_trusted(prompt: 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
|
// macOS >= 10.15
|
||||||
// https://stackoverflow.com/questions/56597221/detecting-screen-recording-settings-on-macos-catalina/
|
// 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
|
// remove just one app from all the permissions: tccutil reset All com.carriez.rustdesk
|
||||||
|
@ -582,6 +582,14 @@ pub fn is_installed_daemon(_prompt: bool) -> bool {
|
|||||||
return true;
|
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]
|
#[inline]
|
||||||
pub fn get_error() -> String {
|
pub fn get_error() -> String {
|
||||||
#[cfg(not(any(feature = "cli")))]
|
#[cfg(not(any(feature = "cli")))]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user