Peekaboo/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift
Peter Steinberger c04b8e7af0 Migrate to Swift 6 with strict concurrency
- Update to swift-tools-version 6.0 and enable StrictConcurrency
- Make all data models and types Sendable for concurrency safety
- Migrate commands from ParsableCommand to AsyncParsableCommand
- Remove AsyncUtils.swift and synchronous bridging patterns
- Update WindowBounds property names to snake_case for consistency
- Ensure all error types conform to Sendable protocol
- Add comprehensive Swift 6 migration documentation

This migration enables full Swift 6 concurrency checking and data race
safety while maintaining backward compatibility with the existing API.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-08 11:23:10 +01:00

32 lines
1.2 KiB
Swift

import AVFoundation
import CoreGraphics
import Foundation
import ScreenCaptureKit
final class PermissionsChecker: Sendable {
static func checkScreenRecordingPermission() -> Bool {
// Use a simpler approach - check CGWindowListCreateImage which doesn't require async
// This is the traditional way to check screen recording permission
let windowList = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID)
return windowList != nil && CFArrayGetCount(windowList) > 0
}
static func checkAccessibilityPermission() -> Bool {
// Check if we have accessibility permission
// Create options dictionary without using the global constant directly
let options = ["AXTrustedCheckOptionPrompt": false] as CFDictionary
return AXIsProcessTrustedWithOptions(options)
}
static func requireScreenRecordingPermission() throws {
if !checkScreenRecordingPermission() {
throw CaptureError.screenRecordingPermissionDenied
}
}
static func requireAccessibilityPermission() throws {
if !checkAccessibilityPermission() {
throw CaptureError.accessibilityPermissionDenied
}
}
}