mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-28 01:43:31 +00:00
Prune unused iOS surfaces and regenerate the Xcode project. Add a scoped Periphery PR gate with hardened artifact handling and stale-status cleanup. Co-authored-by: Sash Zats <sash@zats.io>
85 lines
2.6 KiB
Swift
85 lines
2.6 KiB
Swift
import AVFAudio
|
|
import Foundation
|
|
import OpenClawKit
|
|
import Speech
|
|
|
|
extension TalkModeManager {
|
|
nonisolated static func requestMicrophonePermission() async -> Bool {
|
|
switch AVAudioApplication.shared.recordPermission {
|
|
case .granted:
|
|
return true
|
|
case .denied:
|
|
return false
|
|
case .undetermined:
|
|
return await self.requestPermissionWithTimeout { completion in
|
|
AVAudioApplication.requestRecordPermission(completionHandler: { ok in
|
|
completion(ok)
|
|
})
|
|
}
|
|
@unknown default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
nonisolated static func requestSpeechPermission() async -> Bool {
|
|
let status = SFSpeechRecognizer.authorizationStatus()
|
|
switch status {
|
|
case .authorized:
|
|
return true
|
|
case .denied, .restricted:
|
|
return false
|
|
case .notDetermined:
|
|
break
|
|
@unknown default:
|
|
return false
|
|
}
|
|
|
|
return await self.requestPermissionWithTimeout { completion in
|
|
SFSpeechRecognizer.requestAuthorization { authStatus in
|
|
completion(authStatus == .authorized)
|
|
}
|
|
}
|
|
}
|
|
|
|
private nonisolated static func requestPermissionWithTimeout(
|
|
_ operation: @escaping @Sendable (@escaping @Sendable (Bool) -> Void) -> Void) async -> Bool
|
|
{
|
|
do {
|
|
return try await AsyncTimeout.withTimeout(
|
|
seconds: 8,
|
|
onTimeout: { NSError(domain: "TalkMode", code: 6, userInfo: [
|
|
NSLocalizedDescriptionKey: "permission request timed out",
|
|
]) },
|
|
operation: {
|
|
await withCheckedContinuation(isolation: nil) { cont in
|
|
Task { @MainActor in
|
|
operation { ok in
|
|
cont.resume(returning: ok)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
static func permissionMessage(
|
|
kind: String,
|
|
status: SFSpeechRecognizerAuthorizationStatus) -> String
|
|
{
|
|
switch status {
|
|
case .denied:
|
|
return "\(kind) permission denied"
|
|
case .restricted:
|
|
return "\(kind) permission restricted"
|
|
case .notDetermined:
|
|
return "\(kind) permission not granted"
|
|
case .authorized:
|
|
return "\(kind) permission denied"
|
|
@unknown default:
|
|
return "\(kind) permission denied"
|
|
}
|
|
}
|
|
}
|