diff --git a/core-graphics/src/access.rs b/core-graphics/src/access.rs new file mode 100644 index 0000000..4e852c8 --- /dev/null +++ b/core-graphics/src/access.rs @@ -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; +} diff --git a/core-graphics/src/lib.rs b/core-graphics/src/lib.rs index 5238774..514558f 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -41,3 +41,5 @@ pub mod private; pub mod image; pub mod path; pub mod sys; +#[cfg(target_os = "macos")] +pub mod access; \ No newline at end of file