Review fixes: reindex activeBoardIndex; safer live-input rebuild

- moveBoard/removeBoard now keep activeBoardIndex pointing at the soloed board
  (track by identity on move; shift down or clear on remove), so the Solo
  highlight no longer lights the wrong cell after reorder or delete.
- rebuildWithLiveInput snapshots the rig before any teardown and aborts if the
  snapshot fails, instead of tearing down then seeding a fallback (no silent
  rig loss). The engine-already-has-input early return now also persists the
  live-input selection, via a shared selectLiveInputAndPersist helper.
- Test: activeBoardIndex tracks reorder and removal.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 21:22:44 -07:00
parent 652a5a76ca
commit 6ad813601f
3 changed files with 84 additions and 12 deletions
@@ -124,12 +124,22 @@ final class ShoeGazeBuilderiOSAppModel {
/// selects live input on channel 0. No-op if the engine already has an input channel.
private func rebuildWithLiveInput() {
guard engine.numInputChannels == 0 else {
try? shoeGaze.setInputSource(.liveInput(channel: 0))
// Engine already has an input channel: just select live input, no rebuild.
selectLiveInputAndPersist()
return
}
let wasRunning: Bool = engine.isRunning
let snapshot: Data? = try? shoeGaze.rigData()
// Snapshot the rig BEFORE any teardown. If this fails, abort the rebuild rather than
// tear the engine down and lose the rig — the user stays on the current engine.
let snapshot: Data
do {
snapshot = try shoeGaze.rigData()
} catch {
print("[ShoeGazeBuilderiOS] rig snapshot failed; aborting live-input rebuild: \(error)")
return
}
engine.stop()
shoeGaze.teardown()
@@ -141,17 +151,21 @@ final class ShoeGazeBuilderiOSAppModel {
self.iosDriver = rebuilt.driver
self.shoeGaze = rebuilt.shoeGaze
if let snapshot {
do {
try shoeGaze.loadRig(from: snapshot)
} catch {
print("[ShoeGazeBuilderiOS] rig restore after rebuild failed: \(error)")
seedFallbackBoard()
}
} else {
do {
// Teardown already happened, so a restore failure can only recover by seeding.
try shoeGaze.loadRig(from: snapshot)
} catch {
print("[ShoeGazeBuilderiOS] rig restore after rebuild failed: \(error)")
seedFallbackBoard()
}
selectLiveInputAndPersist()
if wasRunning { try? engine.start() }
}
/// Selects live input on channel 0 and persists the choice for restore-on-relaunch.
private func selectLiveInputAndPersist() {
do {
try shoeGaze.setInputSource(.liveInput(channel: 0))
UserDefaults.standard.set(
@@ -161,8 +175,6 @@ final class ShoeGazeBuilderiOSAppModel {
} catch {
print("[ShoeGazeBuilderiOS] selecting live input failed: \(error)")
}
if wasRunning { try? engine.start() }
}
/// Seeds a single default board so the rig is never empty after a failed restore.