65 lines
2.0 KiB
Plaintext
65 lines
2.0 KiB
Plaintext
#import "Permissions.h"
|
|
#import <Cocoa/Cocoa.h>
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
#import <ApplicationServices/ApplicationServices.h>
|
|
|
|
bool Permissions::checkScreenCapture() {
|
|
// macOS 10.15+ requires screen recording permission
|
|
if (@available(macOS 10.15, *)) {
|
|
// Use CGPreflightScreenCaptureAccess for reliable permission check
|
|
// This API is available since macOS 10.15
|
|
return CGPreflightScreenCaptureAccess();
|
|
}
|
|
|
|
// Before 10.15, no permission needed
|
|
return true;
|
|
}
|
|
|
|
void Permissions::requestScreenCapture() {
|
|
if (@available(macOS 10.15, *)) {
|
|
// Trigger system permission dialog
|
|
CGRequestScreenCaptureAccess();
|
|
}
|
|
}
|
|
|
|
bool Permissions::checkAccessibility() {
|
|
return AXIsProcessTrusted();
|
|
}
|
|
|
|
void Permissions::requestAccessibility() {
|
|
NSDictionary *options = @{
|
|
(__bridge id)kAXTrustedCheckOptionPrompt: @YES
|
|
};
|
|
AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options);
|
|
}
|
|
|
|
void Permissions::openScreenCaptureSettings() {
|
|
if (@available(macOS 10.15, *)) {
|
|
// Open System Preferences -> Security & Privacy -> Privacy -> Screen Recording
|
|
NSURL *url = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"];
|
|
[[NSWorkspace sharedWorkspace] openURL:url];
|
|
}
|
|
}
|
|
|
|
void Permissions::openAccessibilitySettings() {
|
|
// Open System Preferences -> Security & Privacy -> Privacy -> Accessibility
|
|
NSURL *url = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"];
|
|
[[NSWorkspace sharedWorkspace] openURL:url];
|
|
}
|
|
|
|
bool Permissions::checkAllPermissions() {
|
|
return checkScreenCapture() && checkAccessibility();
|
|
}
|
|
|
|
bool Permissions::waitForPermissions(int timeoutSeconds) {
|
|
int elapsed = 0;
|
|
while (elapsed < timeoutSeconds) {
|
|
if (checkAllPermissions()) {
|
|
return true;
|
|
}
|
|
[NSThread sleepForTimeInterval:1.0];
|
|
elapsed++;
|
|
}
|
|
return false;
|
|
}
|