Persist board across restarts + Clear button with save prompt

Persistence (macOS + iOS):
- RigStore autosaves the rig (rigData JSON) to Application Support and restores
  it on launch. App models restore-or-seed at init; macOS saves on terminate +
  resignActive, iOS saves on scenePhase leaving .active. The builder also
  autosaves after structural edits (add board/pedal, load, clear).

Clear (both platforms):
- A Clear button in the builder opens a confirmation dialog: Save & Clear /
  Clear Without Saving / Cancel. Clear removes all boards and seeds one fresh
  empty board, then autosaves. Save & Clear triggers the save mechanism and only
  clears once the save completes (cancelling the save leaves the rig intact).
- The rig-save exporter is now cross-platform (was iOS-only) so Save and the
  Save & Clear flow work on macOS too; macOS keeps its File-menu Load.

Tests: RigStore save/restore round-trip across instances; restore is a no-op
with no autosave. 186 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 18:54:03 -07:00
parent f29ab609bd
commit 0d17ed260b
6 changed files with 240 additions and 32 deletions
+10 -1
View File
@@ -83,7 +83,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
)
super.init()
seedInitialBoard()
// Restore the autosaved rig if there is one; otherwise seed a default board.
if !RigStore.restore(into: shoeGaze) {
seedInitialBoard()
}
}
/// Seeds one board with a single pedal so the builder opens with an audible starting point.
@@ -134,9 +137,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
func applicationWillTerminate(_ notification: Notification) {
RigStore.save(shoeGaze)
engine.stop()
}
func applicationDidResignActive(_ notification: Notification) {
// Persist on every deactivation too, so state survives an unexpected exit.
RigStore.save(shoeGaze)
}
// MARK: - Main menu
/// Builds a minimal menu bar: an application menu with About / Hide / Quit (⌘Q).
@@ -19,6 +19,7 @@ import LyrebirdShoeGazeUI
struct ShoeGazeBuilderiOSApp: App {
@State private var model: ShoeGazeBuilderiOSAppModel = ShoeGazeBuilderiOSAppModel()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
@@ -33,5 +34,9 @@ struct ShoeGazeBuilderiOSApp: App {
}
.onDisappear { model.stop() }
}
.onChange(of: scenePhase) { _, phase in
// Persist the rig whenever the app leaves the foreground.
if phase != .active { model.save() }
}
}
}
@@ -61,15 +61,17 @@ final class ShoeGazeBuilderiOSAppModel {
self.iosDriver = built.driver
self.shoeGaze = built.shoeGaze
do {
let board: PedalBoard = try shoeGaze.addBoard()
board.label = "Board 1"
try shoeGaze.appendPedal(ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
} catch {
print("[ShoeGazeBuilderiOS] seed board failed: \(error)")
// Restore the autosaved rig if there is one; otherwise seed a default board.
if !RigStore.restore(into: shoeGaze) {
seedFallbackBoard()
}
}
/// Persists the current rig. Call when the app moves to the background.
func save() {
RigStore.save(shoeGaze)
}
// MARK: - Audio session / engine construction
/// Activates the play-and-record audio session once. Idempotent; safe to call before each