blitztext-app-linux/BlitztextMac/Services/AccessibilityPermissionService.swift
2026-05-23 07:28:46 +02:00

35 lines
1.1 KiB
Swift

import AppKit
import ApplicationServices
@MainActor
enum AccessibilityPermissionService {
private static var hasPromptedThisSession = false
static func currentStatus() -> Bool {
AXIsProcessTrusted()
}
static func isTrusted(promptIfNeeded: Bool) -> Bool {
let shouldPrompt = promptIfNeeded && !hasPromptedThisSession
if shouldPrompt {
hasPromptedThisSession = true
}
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: shouldPrompt] as CFDictionary
return AXIsProcessTrustedWithOptions(options)
}
static func requestPermissionPrompt() -> Bool {
hasPromptedThisSession = true
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary
return AXIsProcessTrustedWithOptions(options)
}
static func openSystemSettings() {
guard let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility") else {
return
}
NSWorkspace.shared.open(url)
}
}