macdriver icon indicating copy to clipboard operation
macdriver copied to clipboard

macos/screencapturekit: add support with TCC error handling and example

Open tmc opened this issue 10 months ago • 1 comments

This PR adds support for Apple's ScreenCaptureKit framework to DarwinKit with comprehensive TCC (Transparency, Consent, and Control) permission handling.

Features

Core Screenshot Functionality

  • SCScreenshotManager for taking screenshots
  • Proper error handling via SCError type
  • Modern DarwinKit API design using objc.Call pattern

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

  • SCStreamConfiguration for screen capture configuration
  • SCContentFilter for filtering capture content
  • SCDisplay and SCWindow type 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...
})

tmc avatar Mar 02 '25 12:03 tmc

claude generated? if we ran clobber and this package was deleted, how would it be regenerated?

progrium avatar Mar 08 '25 18:03 progrium