mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
Apple's speech daemon can stop answering during preparation: the asset reservation, the status checks before and after a download, the language lookup, the network check and the release had no time limit. They are now watched at 60 s with StallWatch's suspension-aware deadline, a reservation or release that never answers is forgotten so the next attempt asks again, and a call whose success another caller already gave up on is retried rather than believed. A keyboard check that only hangs counts no strike toward Hex's handoff. A preparation a newer one replaces, or one the preparation watch ends, is cancelled, and the keyboard's publish and handoff paths ignore a cancelled check, so a late answer can't reopen the row. The keyboard's model check retries after a real background trip. The multilingual download's restart cancels and awaits the old transfer before resuming its .partial file, and a preparation that ends in the background is retried on return.
30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
/// Preparation never answered: a Speech call that never returns, rather than a download that
|
|
/// stopped. The failure offers Try again, so the screen never stays on "Checking the speech
|
|
/// model" forever.
|
|
nonisolated struct SpeechModelUnresponsive: HexDescribedError {
|
|
var errorDescription: String? {
|
|
String(localized: "The speech model isn't ready. Try again.")
|
|
}
|
|
}
|
|
|
|
/// Runs one Apple step under `StallWatch`'s deadline, which doesn't count time iOS has Hex
|
|
/// suspended, and reports it as `SpeechModelUnresponsive` instead of a stopped download. The
|
|
/// step reports no progress of its own, so the whole wait is bounded.
|
|
nonisolated enum SpeechModelDeadline {
|
|
static func run<T: Sendable>(
|
|
_ limit: Duration,
|
|
operation: @escaping @Sendable () async throws -> T
|
|
) async throws -> T {
|
|
do {
|
|
return try await StallWatch.run(
|
|
limit: limit,
|
|
progress: { () -> Double? in 0 },
|
|
operation: operation
|
|
)
|
|
} catch is StallWatch.Stalled {
|
|
throw SpeechModelUnresponsive()
|
|
}
|
|
}
|
|
}
|