Extracted the PreviewPreinstalling service in the Sample app target into its own file and declared it as development asset.
This commit is contained in:
@@ -15,6 +15,9 @@ extension ContentView {
|
||||
/// Every picked locale kicks off ``preinstall()``, a cancellable task that preinstalls the locale's speech model assets through the
|
||||
/// preinstalling service — cancelling any download still in flight for a previously picked locale. The service's started, cancelled, and
|
||||
/// failed download events are mapped to the transient, self-dismissing notifications of the ``notifier``.
|
||||
///
|
||||
/// Every collaborator is injected at initialization behind its protocol, defaulting to the on-device services: the app runs the model
|
||||
/// against the real backends, while its unit tests and previews attach mocks and dummies without touching this type.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class Model {
|
||||
@@ -84,9 +87,10 @@ extension ContentView {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
/// Loads the locales the transcriber supports into ``locales``, sorted by their localized names, and aligns ``locale`` with the
|
||||
/// supported equivalent of its current value — falling back to the supported equivalent of a default locale when none exists —
|
||||
/// so the locale picker starts with a valid selection.
|
||||
/// Loads the locales the transcriber supports — resolved through the preinstalling service — into ``locales``, sorted by their
|
||||
/// localized names, and aligns ``locale`` with the supported equivalent of its current value — falling back to the supported
|
||||
/// equivalent of a default locale when none exists — so the locale picker starts with a valid selection. It then kicks off the
|
||||
/// preinstallation of the aligned locale's speech model assets.
|
||||
func load() async {
|
||||
locales =
|
||||
await preinstaller
|
||||
|
||||
@@ -12,7 +12,7 @@ import SwiftUI
|
||||
///
|
||||
/// The services attached to the feature, the transcription shown in the sheet, and the notifier owning the notifications live in the view's
|
||||
/// ``Model``; the view itself only renders it and forwards the feature's output, the picker's changes, and the sheet's dismissal. All
|
||||
/// user-facing text is localized through the app's string catalog.
|
||||
/// user-facing text is localized through the app's string catalog, resolved via its generated string symbols.
|
||||
struct ContentView: View {
|
||||
|
||||
// MARK: Properties
|
||||
@@ -220,35 +220,6 @@ private enum Constant {
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
/// The preinstalling service used by the previews, which resolves every locale as supported and downloads nothing.
|
||||
private struct PreviewPreinstalling: Preinstalling {
|
||||
|
||||
/// The stream of events the service emits, which finishes immediately.
|
||||
let events: AsyncStream<PreinstallingEvent> = .init { continuation in
|
||||
continuation.finish()
|
||||
}
|
||||
|
||||
func preinstall(
|
||||
for locale: Locale
|
||||
) async {
|
||||
// The previews preinstall no speech model assets.
|
||||
}
|
||||
|
||||
func supportedLocale(
|
||||
equivalentTo locale: Locale
|
||||
) async -> Locale? {
|
||||
locale
|
||||
}
|
||||
|
||||
func supportedLocales() async -> [Locale] {
|
||||
[
|
||||
Locale(identifier: "en-US"),
|
||||
Locale(identifier: "nl-NL"),
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#Preview(
|
||||
"Content view"
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user