Restore rig highlight by id, paired with autosave
The previous fix derived the highlight by full-state equality against library entries, which broke as soon as the working rig was edited — e.g. after learning a MIDI binding, the working midiMap no longer equalled the saved entry, so nothing was highlighted on restart. Revert to an id-based highlight (survives edits, since edits don't change which saved rig the session derives from) and additionally persist the current-rig id on every autosave, so the stored id can never drift from the autosaved graph — which was the original cause of the highlight/graph mismatch. Both app targets build; suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -699,6 +699,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// survives a restart even without an explicit Save; the app shells also save on background.
|
||||
private func autosave() {
|
||||
RigStore.save(shoeGaze)
|
||||
// Pair the current-rig id with every graph write so the persisted highlight can never drift
|
||||
// from the autosaved graph (the source of the highlight/graph mismatch on restart).
|
||||
persistCurrentRigID()
|
||||
}
|
||||
|
||||
/// Removes every board, then seeds one fresh empty board so the builder is never boardless.
|
||||
@@ -874,21 +877,21 @@ public struct ShoeGazeBuilderView: View {
|
||||
|
||||
// MARK: - Rig library
|
||||
|
||||
/// Highlights the library entry that matches the restored working rig, once the library has
|
||||
/// loaded. Runs once.
|
||||
/// Highlights the rig the working session derives from, once the library has loaded. Runs once.
|
||||
///
|
||||
/// The working graph is restored from the autosave file independently of any persisted
|
||||
/// selection, so the highlight is derived from the *actual* loaded graph rather than a separate
|
||||
/// stored id (which could point at a different rig and mislabel what's shown). If the working
|
||||
/// graph is an unsaved/edited session that matches no saved entry, nothing is highlighted.
|
||||
/// The current rig id is written paired with every autosave (see ``autosave()``), so the stored
|
||||
/// id always tracks the loaded graph — including after edits such as learning a MIDI binding,
|
||||
/// which change the graph but not which saved rig it came from. Only highlights when nothing is
|
||||
/// selected yet and the saved id still exists in the library.
|
||||
private func restoreCurrentRig() {
|
||||
guard !didRestoreRig, library.isLoaded else { return }
|
||||
didRestoreRig = true
|
||||
guard currentRigID == nil else { return }
|
||||
let working: ShoeGazeState = shoeGaze.captureState()
|
||||
if let match: RigEntry = library.entries.first(where: { $0.state == working }) {
|
||||
currentRigID = match.id
|
||||
}
|
||||
guard currentRigID == nil,
|
||||
let stored: String = UserDefaults.standard.string(
|
||||
forKey: ShoeGazeBuilderView.currentRigDefaultsKey),
|
||||
let id: UUID = UUID(uuidString: stored),
|
||||
library.entries.contains(where: { $0.id == id }) else { return }
|
||||
currentRigID = id
|
||||
}
|
||||
|
||||
/// Persists `currentRigID` so the same rig is highlighted on the next launch.
|
||||
|
||||
Reference in New Issue
Block a user