31f5937a7f
Reduce extension memory pressure and delivery races while adding richer candidates, tactile feedback, and safer two-level creative polishing.
51 lines
1.4 KiB
Swift
51 lines
1.4 KiB
Swift
// MicVoiceAvailability+Keyboard.swift
|
|
// OSGKeyboard · Shared
|
|
//
|
|
// Derives keyboard mic availability from pipeline phase and host readiness.
|
|
|
|
import Foundation
|
|
|
|
public enum MicVoiceAvailabilityResolver {
|
|
public static func resolve(
|
|
phase: KeyboardState.Phase,
|
|
micDisabled: Bool,
|
|
hasFullAccess: Bool,
|
|
appGroupAvailable: Bool,
|
|
hostReady: Bool,
|
|
isPreparingSession: Bool,
|
|
hasCompletedOnboarding: Bool = true
|
|
) -> MicVoiceAvailability {
|
|
switch phase {
|
|
case .recording:
|
|
return .recording
|
|
case .processing, .requestingPermissions:
|
|
return .processing
|
|
case .error, .denied:
|
|
return .unavailable(.hostNotReady)
|
|
case .idle:
|
|
break
|
|
}
|
|
|
|
// Host owns setup; keyboard only gates voice until that finishes.
|
|
if !hasCompletedOnboarding {
|
|
return .unavailable(.onboardingIncomplete)
|
|
}
|
|
if !appGroupAvailable {
|
|
return .unavailable(.appGroupUnavailable)
|
|
}
|
|
if !hasFullAccess {
|
|
return .unavailable(.noFullAccess)
|
|
}
|
|
if micDisabled {
|
|
return .unavailable(.missingAPIKey)
|
|
}
|
|
if isPreparingSession {
|
|
return .unavailable(.preparingSession)
|
|
}
|
|
if hostReady {
|
|
return .ready
|
|
}
|
|
return .unavailable(.hostNotReady)
|
|
}
|
|
}
|