Make rig library loads/resolve fully off-main
Move the remaining synchronous main-thread I/O off the main actor: - RigLibraryStore now constructs instantly with a local placeholder and exposes an awaitable async start(): it resolves the iCloud-or-local location off-main (the blocking ubiquity lookup), loads entries off-main via the shared ioQueue (so a reload can't drop a just-saved rig), then sets isLoaded. reload() is async; iCloud metadata updates re-read via it. - Seeding moves into RigLibraryBootstrap.start(_:seedFrom:), which seeds a "Default" rig only AFTER the (possibly iCloud) library has loaded and is still empty — preventing a duplicate "Default" on every synced device on first launch. - Sidebar shows a Loading state until isLoaded; the builder restores the persisted current-rig highlight when isLoaded flips true (initialRigID param dropped). - Shells construct the store synchronously and start it asynchronously (macOS via Task in didFinishLaunching; iOS via .task). Codec + file helpers are nonisolated static so background work needs no actor hop. - Tests await store.start(). Full suite: 206 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -27,12 +27,12 @@ struct ShoeGazeBuilderiOSApp: App {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
library: model.library,
|
||||
initialRigID: model.initialRigID,
|
||||
hardwareSampleRate: { model.hardwareSampleRate },
|
||||
onEnableLiveInput: { model.enableLiveInput() }
|
||||
)
|
||||
.navigationTitle("ShoeGaze Builder")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.task { await model.startLibrary() }
|
||||
}
|
||||
.onDisappear { model.stop() }
|
||||
}
|
||||
|
||||
@@ -56,14 +56,10 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
||||
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
||||
|
||||
/// The library entry to highlight as current on this launch (and after an engine rebuild),
|
||||
/// resolved live from the persisted id so a mid-session selection survives a rebuild.
|
||||
var initialRigID: UUID? {
|
||||
guard let stored: String = UserDefaults.standard.string(
|
||||
forKey: ShoeGazeBuilderView.currentRigDefaultsKey),
|
||||
let id: UUID = UUID(uuidString: stored),
|
||||
library.entries.contains(where: { $0.id == id }) else { return nil }
|
||||
return id
|
||||
/// Resolves iCloud + loads the library off the main thread, then seeds it from the working rig
|
||||
/// on first run. Call once from the app's `.task`. Safe to call again (no-op once non-empty).
|
||||
func startLibrary() async {
|
||||
await RigLibraryBootstrap.start(library, seedFrom: shoeGaze)
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
@@ -84,8 +80,9 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
ShoeGazeBuilderiOSAppModel.seedFallbackBoard(into: shoeGaze)
|
||||
}
|
||||
|
||||
// Bootstrap the rig library (iCloud-or-local), seeding it from the working rig on first run.
|
||||
self.library = RigLibraryBootstrap.make(for: shoeGaze).store
|
||||
// Construct the library instantly; it resolves iCloud + loads asynchronously via
|
||||
// startLibrary() from the app's .task.
|
||||
self.library = RigLibraryBootstrap.makeStore()
|
||||
}
|
||||
|
||||
/// Persists the current rig. Call when the app moves to the background.
|
||||
|
||||
Reference in New Issue
Block a user