Peekaboo/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift
Peter Steinberger de5a0cb97e Fix Screen Recording permission detection and improve error reporting
- Replace broken CGDisplayBounds check with ScreenCaptureKit API
- Add proper error handling to detect permission-related failures
- Add server_status subcommand to expose permission status via JSON
- Ensure users get clear error messages when permissions are missing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-07 22:51:49 +01:00

46 lines
1.5 KiB
Swift

import AVFoundation
import CoreGraphics
import Foundation
import ScreenCaptureKit
class PermissionsChecker {
static func checkScreenRecordingPermission() -> Bool {
// ScreenCaptureKit requires screen recording permission
// We check by attempting to get shareable content
let semaphore = DispatchSemaphore(value: 0)
var hasPermission = false
Task {
do {
// This will fail if we don't have screen recording permission
_ = try await SCShareableContent.current
hasPermission = true
} catch {
// If we get an error, we don't have permission
hasPermission = false
}
semaphore.signal()
}
semaphore.wait()
return hasPermission
}
static func checkAccessibilityPermission() -> Bool {
// Check if we have accessibility permission
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: false]
return AXIsProcessTrustedWithOptions(options as CFDictionary)
}
static func requireScreenRecordingPermission() throws {
if !checkScreenRecordingPermission() {
throw CaptureError.screenRecordingPermissionDenied
}
}
static func requireAccessibilityPermission() throws {
if !checkAccessibilityPermission() {
throw CaptureError.accessibilityPermissionDenied
}
}
}