use exit codes to indicate permission
This commit is contained in:
@@ -14,12 +14,5 @@ let package = Package(
|
|||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
.define("ENABLE_TCC_SPI")
|
.define("ENABLE_TCC_SPI")
|
||||||
])
|
])
|
||||||
// linkerSettings: [
|
|
||||||
// .unsafeFlags([
|
|
||||||
// "-Xlinker", "-sectcreate",
|
|
||||||
// "-Xlinker", "__TEXT",
|
|
||||||
// "-Xlinker", "__info_plist",
|
|
||||||
// "-Xlinker", "Resources/Info.plist",
|
|
||||||
// ])
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>NSAudioCaptureUsageDescription</key>
|
|
||||||
<string>This application requires access to system audio to record and stream audio output to external services such as speech recognition APIs.</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -118,8 +118,8 @@ struct AudioTee {
|
|||||||
func run() throws {
|
func run() throws {
|
||||||
// Handle permissions mode
|
// Handle permissions mode
|
||||||
if permissionsMode {
|
if permissionsMode {
|
||||||
try handlePermissions()
|
let permissionsHandler = PermissionsHandler(shouldRequest: requestPermissions)
|
||||||
return
|
permissionsHandler.handle() // This will exit with appropriate code
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with normal audio tapping functionality
|
// Continue with normal audio tapping functionality
|
||||||
@@ -185,44 +185,6 @@ struct AudioTee {
|
|||||||
recorder.stopRecording()
|
recorder.stopRecording()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handlePermissions() throws {
|
|
||||||
let permissionHandler = AudioRecordingPermission()
|
|
||||||
|
|
||||||
if requestPermissions {
|
|
||||||
// Request permissions
|
|
||||||
print("Requesting audio recording permissions...")
|
|
||||||
print("Initial status: \(permissionHandler.status.rawValue)")
|
|
||||||
|
|
||||||
// Trigger the request
|
|
||||||
permissionHandler.request()
|
|
||||||
print("Request method called...")
|
|
||||||
|
|
||||||
// Wait for status to change from unknown with some progress indication
|
|
||||||
var waitCount = 0
|
|
||||||
while permissionHandler.status == .unknown {
|
|
||||||
// Run the main run loop to allow DispatchQueue.main.async to execute
|
|
||||||
let result = CFRunLoopRunInMode(CFRunLoopMode.defaultMode, 0.1, true)
|
|
||||||
if result == CFRunLoopRunResult.stopped || result == CFRunLoopRunResult.finished {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
waitCount += 1
|
|
||||||
if waitCount % 50 == 0 { // Every 5 seconds (50 * 0.1)
|
|
||||||
print(
|
|
||||||
"Still waiting for permission response... (status: \(permissionHandler.status.rawValue))"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Permission status: \(permissionHandler.status.rawValue)")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Just check current permissions
|
|
||||||
let status = permissionHandler.status
|
|
||||||
print("Current permission status: \(status.rawValue)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setupSignalHandlers() {
|
private func setupSignalHandlers() {
|
||||||
signal(SIGINT) { _ in
|
signal(SIGINT) { _ in
|
||||||
Logger.info("Received SIGINT, initiating graceful shutdown...")
|
Logger.info("Received SIGINT, initiating graceful shutdown...")
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import CoreFoundation
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Handles audio recording permissions for the CLI, including checking status and requesting permissions.
|
||||||
|
/// Uses exit codes to communicate permission status:
|
||||||
|
/// - 0: granted (authorized)
|
||||||
|
/// - 1: unknown
|
||||||
|
/// - 2: denied
|
||||||
|
struct PermissionsHandler {
|
||||||
|
private let shouldRequest: Bool
|
||||||
|
|
||||||
|
init(shouldRequest: Bool) {
|
||||||
|
self.shouldRequest = shouldRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handles the permissions workflow and exits with appropriate exit code
|
||||||
|
func handle() -> Never {
|
||||||
|
let permissionHandler = AudioRecordingPermission()
|
||||||
|
|
||||||
|
if shouldRequest {
|
||||||
|
print("Requesting audio recording permissions...")
|
||||||
|
permissionHandler.request()
|
||||||
|
|
||||||
|
// Wait for the permission request to complete
|
||||||
|
while permissionHandler.status == .unknown {
|
||||||
|
// Run the main run loop to allow DispatchQueue.main.async to execute
|
||||||
|
let result = CFRunLoopRunInMode(CFRunLoopMode.defaultMode, 0.1, true)
|
||||||
|
if result == CFRunLoopRunResult.stopped || result == CFRunLoopRunResult.finished {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get final status and exit with appropriate code
|
||||||
|
let status = permissionHandler.status
|
||||||
|
print("Audio recording permission status: \(status.rawValue)")
|
||||||
|
|
||||||
|
switch status {
|
||||||
|
case .authorized:
|
||||||
|
exit(0) // granted
|
||||||
|
case .unknown:
|
||||||
|
exit(1) // unknown
|
||||||
|
case .denied:
|
||||||
|
exit(2) // denied
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user