xcap icon indicating copy to clipboard operation
xcap copied to clipboard

Is there a way to check this before the screen capture permission pop up on macos?

Open gusxodnjs opened this issue 1 year ago • 2 comments

When I try to screen capture in macos, I get a pop-up if I don't have permission. I want to replace this pop-up with my custom pop-up. Is there a way to look up the system's settings before this pop-up pops up? I already know that I can access tcc.db to verify permissions, but I couldn't access this db in my application.

gusxodnjs avatar Jul 19 '24 06:07 gusxodnjs

@gusxodnjs interested about it too, do you know what to put in entitlements.plist and Info.plist also for permissions?

louis030195 avatar Jul 22 '24 08:07 louis030195

Use this module


// screen_capture.rs

// Use the objc crate to work with Objective-C objects and runtime
extern crate objc;

// Import necessary parts from the objc crate
use objc::runtime::Object;
use std::os::raw::c_void;

// Declare the external functions from CoreGraphics framework
extern "C" {
    // CGPreflightScreenCaptureAccess doesn't take parameters and returns a bool.
    // True if the app either already has screen capture access or if the system
    // version is earlier than 10.15. False otherwise.
    fn CGPreflightScreenCaptureAccess() -> bool;

    // CGRequestScreenCaptureAccess doesn't take parameters and returns a bool.
    // True if the user grants permission or if the app already has permission.
    // False if the user denies permission or if an error occurs.
    fn CGRequestScreenCaptureAccess() -> bool;
}

/// Check if the user has already granted screen capture access or if the system
/// version is earlier than 10.15.
pub fn preflight_access() -> bool {
    unsafe {
        // Safety: Calling an external C function, considered unsafe in Rust
        CGPreflightScreenCaptureAccess()
    }
}

/// Request screen capture access from the user.
pub fn request_access() -> bool {
    unsafe {
        // Safety: Calling an external C function, considered unsafe in Rust
        CGRequestScreenCaptureAccess()
    }
}

codesoda avatar Aug 17 '24 09:08 codesoda