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:
2026-06-27 19:50:38 -07:00
parent 849240e6e2
commit 9a8e5461c0
9 changed files with 175 additions and 133 deletions
+9 -9
View File
@@ -55,9 +55,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private let shoeGaze: ShoeGaze
private let window: LyrebirdWindow
/// The rig library and the entry to highlight at launch; built in `init`.
/// The rig library; constructed in `init`, resolved + loaded asynchronously after launch.
private let library: RigLibraryStore
private let initialRigID: UUID?
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
private var recordMenuItem: NSMenuItem?
@@ -88,14 +87,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
)
// Stored `let`s must be set before `super.init()`. Restore the autosaved working rig (or
// seed a board), then bootstrap the rig library from it — all operating on `shoeGaze`, not
// on `self` methods (which aren't available pre-`super.init`).
// seed a board) — operating on `shoeGaze`, not on `self` methods (unavailable pre-super).
if !RigStore.restore(into: shoeGaze) {
AppDelegate.seedInitialBoard(into: shoeGaze)
}
let bootstrap: RigLibraryBootstrap.Result = RigLibraryBootstrap.make(for: shoeGaze)
self.library = bootstrap.store
self.initialRigID = bootstrap.initialRigID
// The library constructs instantly; it resolves iCloud + loads asynchronously after launch.
self.library = RigLibraryBootstrap.makeStore()
super.init()
}
@@ -120,16 +117,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let session: ShoeGaze = shoeGaze
let driver: CoreAudioDriver = coreDriver
let rigLibrary: RigLibraryStore = library
let startupRigID: UUID? = initialRigID
window.open {
ShoeGazeBuilderView(
shoeGaze: session,
library: rigLibrary,
initialRigID: startupRigID,
hardwareSampleRate: { driver.deviceSampleRate }
)
}
anchorWindowLeft()
// Resolve iCloud + load the library off the main thread, then seed from the working rig if
// it is still empty (first run).
let rigSession: ShoeGaze = shoeGaze
Task { await RigLibraryBootstrap.start(rigLibrary, seedFrom: rigSession) }
}
/// Anchors the window `leftMargin` points from the left of the visible screen and sizes it to