Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gusxodnjs opened this issue Jul 19, 2024 · 2 comments

Comments

@gusxodnjs
Copy link

gusxodnjs commented Jul 19, 2024

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 gusxodnjs reopened this Jul 20, 2024
@louis030195
Copy link

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

@codesoda
Copy link

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()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants