Peekaboo/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift
Peter Steinberger 670e1c485a Add GitHub Actions CI workflow for Node.js builds
- Configure CI to run on macOS-latest
- Test with Node.js 20.x and 22.x
- Run npm build and tests on push/PR

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-25 01:25:35 +02:00

47 lines
No EOL
1.5 KiB
Swift

import Foundation
import CoreGraphics
import AVFoundation
class PermissionsChecker {
static func checkScreenRecordingPermission() -> Bool {
// Check if we can capture screen content by trying to get display bounds
var displayCount: UInt32 = 0
let result = CGGetActiveDisplayList(0, nil, &displayCount)
if result != .success || displayCount == 0 {
return false
}
// Try to capture a small image to test permissions
guard let mainDisplayID = CGMainDisplayID() as CGDirectDisplayID? else {
return false
}
// Test by trying to get display bounds - this requires screen recording permission
let bounds = CGDisplayBounds(mainDisplayID)
return bounds != CGRect.zero
}
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(CaptureError) {
if !checkScreenRecordingPermission() {
throw CaptureError.capturePermissionDenied
}
}
static func requireAccessibilityPermission() throws(CaptureError) {
if !checkAccessibilityPermission() {
throw CaptureError.capturePermissionDenied
}
}
}
enum PermissionError: Error {
case screenRecordingDenied
case accessibilityDenied
}