macdriver
macdriver copied to clipboard
macos/screencapturekit: add support with TCC error handling and example
This PR adds support for Apple's ScreenCaptureKit framework to DarwinKit with comprehensive TCC (Transparency, Consent, and Control) permission handling.
Features
Core Screenshot Functionality
SCScreenshotManagerfor taking screenshots- Proper error handling via
SCErrortype - Modern DarwinKit API design using
objc.Callpattern
TCC Permission Handling
- Comprehensive error detection for TCC-related issues
- Helper methods to identify and handle permission errors
- User-friendly guidance for resolving permission problems
- System Preferences integration for easier permission granting
- Automatic retry mechanism for temporary permission issues
Additional Types
SCStreamConfigurationfor screen capture configurationSCContentFilterfor filtering capture contentSCDisplayandSCWindowtype definitions for future expansion
Example Application
- Added screenshot example demonstrating proper usage
- Shows permission handling with retry logic
- Provides user guidance for resolving permission issues
- Saves screenshots to the desktop
Usage Example
// Basic usage
manager := screencapturekit.SCScreenshotManager_SharedManager()
manager.CaptureScreenshotWithCompletion(func(image appkit.Image, err screencapturekit.SCError) {
if \!err.IsNil() {
fmt.Printf("Error: %v\n", err)
return
}
// Process the image...
})
// With retry logic for TCC permission issues
manager.CaptureScreenshotWithRetry(3, time.Second, func(image appkit.Image, err screencapturekit.SCError, success bool) {
if \!success {
if err.IsTCCError() {
fmt.Println(err.GetPermissionInstructions())
screencapturekit.OpenSystemPreferencesTCC()
}
return
}
// Process the image...
})
claude generated? if we ran clobber and this package was deleted, how would it be regenerated?