Auto merge of #554 - fcfangcc:feat-screenCaptureAccess, r=jdm

Add binding for ScreenCaptureAccess

Add binding for [CGRequestScreenCaptureAccess](https://developer.apple.com/documentation/coregraphics/3656524-cgrequestscreencaptureaccess) and [CGPreflightScreenCaptureAccess](https://developer.apple.com/documentation/coregraphics/3656523-cgpreflightscreencaptureaccess)

 to check if the app has screen recording permission on macOS
This commit is contained in:
bors-servo
2023-05-24 15:53:08 +02:00
committed by GitHub
2 changed files with 28 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
pub use base::boolean_t;
#[derive(Default)]
pub struct ScreenCaptureAccess;
impl ScreenCaptureAccess {
/// If current app not in list, will open window.
/// Return the same result as preflight.
#[inline]
pub fn request(&self) -> bool {
unsafe { CGRequestScreenCaptureAccess() == 1 }
}
/// Return true if has access
#[inline]
pub fn preflight(&self) -> bool {
unsafe { CGPreflightScreenCaptureAccess() == 1 }
}
}
#[link(name = "CoreGraphics", kind = "framework")]
extern "C" {
// Screen Capture Access
fn CGRequestScreenCaptureAccess() -> boolean_t;
fn CGPreflightScreenCaptureAccess() -> boolean_t;
}
+2
View File
@@ -41,3 +41,5 @@ pub mod private;
pub mod image;
pub mod path;
pub mod sys;
#[cfg(target_os = "macos")]
pub mod access;