mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-17 13:15:49 +00:00
- 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>
46 lines
1.5 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|