43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
import AppKit
|
|
import AVFoundation
|
|
|
|
enum Permissions {
|
|
enum MicStatus {
|
|
case granted, denied, undetermined
|
|
}
|
|
|
|
static var microphone: MicStatus {
|
|
switch AVCaptureDevice.authorizationStatus(for: .audio) {
|
|
case .authorized: return .granted
|
|
case .denied, .restricted: return .denied
|
|
case .notDetermined: return .undetermined
|
|
@unknown default: return .undetermined
|
|
}
|
|
}
|
|
|
|
static var accessibility: Bool {
|
|
AXIsProcessTrusted()
|
|
}
|
|
|
|
static func requestMicrophone() async -> Bool {
|
|
switch AVCaptureDevice.authorizationStatus(for: .audio) {
|
|
case .authorized:
|
|
return true
|
|
case .notDetermined:
|
|
return await AVCaptureDevice.requestAccess(for: .audio)
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
static func promptAccessibility() {
|
|
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary
|
|
AXIsProcessTrustedWithOptions(options)
|
|
}
|
|
|
|
static func openPrivacyPane(_ pane: String) {
|
|
let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?\(pane)")!
|
|
NSWorkspace.shared.open(url)
|
|
}
|
|
}
|