dc42db0c59
Replace the single hand-saved rig file with a managed library of named rigs persisted in app storage and synced across devices and both builder apps via a shared iCloud container (iCloud.net.realizedsound.ShoeGazeData), falling back to local storage when iCloud is unavailable. Core (LyrebirdShoeGaze/Presets): - RigEntry: named, timestamped ShoeGazeState (a whole multi-board rig). - RigArchive: portable multi-rig JSON bundle for backup/transfer; legacy single-rig files import as a one-rig archive. - RigLibraryStore (@MainActor @Observable): one JSON file per rig, with NSFileCoordinator writes and NSMetadataQuery live remote-change watching. - RigLibraryLocation: iCloud-or-local directory resolver (skips the slow ubiquity lookup when no iCloud account is signed in). - ShoeGaze.loadRig(from: ShoeGazeState) + captureEntry; shared filename sanitizer factored out of BoardVersionStore. UI (LyrebirdShoeGazeUI): - RigLibrarySidebarView: persistent left listing with new/save/save-as/ duplicate/rename/delete/erase-all and archive import/export. - RigNamePrompt; RigLibraryBootstrap one-call shell setup. - ShoeGazeBuilderView: sidebar wired in; selecting a rig replaces the session; File menu / sidebar do whole-library archive import/export. Shells/entitlements: both builder targets own+start the store and carry the iCloud Documents entitlement; NSUbiquitousContainers exposes the rigs in the Files app. (macOS pbxproj also carries a pre-existing 1.0->1.1.1 version bump.) Tests: RigEntry/RigArchive round-trip + RigLibraryStore CRUD/import/export (15 new; full suite 206 passing). Provisioning (manual, not done here): enable the iCloud container on both App IDs and select it in Signing & Capabilities for both targets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
160 lines
5.8 KiB
Swift
160 lines
5.8 KiB
Swift
// RigLibrarySidebarView.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftUI
|
|
import LyrebirdShoeGaze
|
|
|
|
/// The rig library: a persistent left-hand listing of every saved rig, with controls to start a
|
|
/// new rig, save / save-as, duplicate, rename, delete, erase all, and import / export an archive.
|
|
///
|
|
/// Selecting a rig replaces the current working session (the host stops the engine, rebuilds the
|
|
/// graph, and restarts). This view is purely presentational — every action is delegated to the
|
|
/// host (`ShoeGazeBuilderView`) via closures so engine lifecycle and naming prompts stay in one
|
|
/// place.
|
|
struct RigLibrarySidebarView: View {
|
|
|
|
// MARK: - Layout constants
|
|
|
|
private static let width: CGFloat = 200
|
|
private static let rowSpacing: CGFloat = 4
|
|
private static let rowPadding: CGFloat = 8
|
|
private static let rowCorner: CGFloat = 6
|
|
private static let selectedOpacity: Double = 0.22
|
|
private static let subtitleOpacity: Double = 0.5
|
|
private static let headerOpacity: Double = 0.65
|
|
private static let emptyOpacity: Double = 0.4
|
|
|
|
// MARK: - Inputs
|
|
|
|
let store: RigLibraryStore
|
|
|
|
/// The library entry currently loaded into the session, or `nil` for an unsaved/new rig.
|
|
@Binding var currentRigID: UUID?
|
|
|
|
let onSelect: (RigEntry) -> Void
|
|
let onNew: () -> Void
|
|
let onSave: () -> Void
|
|
let onSaveAs: () -> Void
|
|
let onDuplicate: (RigEntry) -> Void
|
|
let onRename: (RigEntry) -> Void
|
|
let onDelete: (RigEntry) -> Void
|
|
let onEraseAll: () -> Void
|
|
let onImportArchive: () -> Void
|
|
let onExportArchive: () -> Void
|
|
|
|
private static let timestampFormat: Date.FormatStyle =
|
|
Date.FormatStyle(date: .abbreviated, time: .shortened)
|
|
|
|
// MARK: - Body
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: RigLibrarySidebarView.rowSpacing) {
|
|
header
|
|
Divider().overlay(Color.white.opacity(0.12))
|
|
rigList
|
|
Divider().overlay(Color.white.opacity(0.12))
|
|
actionBar
|
|
}
|
|
.frame(width: RigLibrarySidebarView.width)
|
|
}
|
|
|
|
// MARK: - Header
|
|
|
|
private var header: some View {
|
|
HStack(spacing: 6) {
|
|
Text("Rigs")
|
|
.font(.headline)
|
|
.foregroundStyle(Color.white)
|
|
Spacer()
|
|
// Cloud icon when the library is iCloud-backed; a slash when local-only.
|
|
Image(systemName: store.isICloud ? "icloud" : "icloud.slash")
|
|
.font(.caption)
|
|
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.headerOpacity))
|
|
.help(store.isICloud
|
|
? "Synced with iCloud across your devices"
|
|
: "iCloud unavailable — rigs are stored on this device only")
|
|
}
|
|
}
|
|
|
|
// MARK: - List
|
|
|
|
private var rigList: some View {
|
|
ScrollView(.vertical, showsIndicators: true) {
|
|
LazyVStack(alignment: .leading, spacing: RigLibrarySidebarView.rowSpacing) {
|
|
if store.entries.isEmpty {
|
|
Text("No saved rigs yet.\nTap New or Save to add one.")
|
|
.font(.caption)
|
|
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
|
|
.padding(.vertical, RigLibrarySidebarView.rowPadding)
|
|
}
|
|
ForEach(store.entries) { entry in
|
|
rigRow(entry)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
|
|
private func rigRow(_ entry: RigEntry) -> some View {
|
|
let isSelected: Bool = entry.id == currentRigID
|
|
return Button {
|
|
onSelect(entry)
|
|
} label: {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(entry.name)
|
|
.font(.subheadline)
|
|
.foregroundStyle(Color.white)
|
|
.lineLimit(1)
|
|
Text(entry.savedAt.formatted(RigLibrarySidebarView.timestampFormat))
|
|
.font(.caption2)
|
|
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.subtitleOpacity))
|
|
.lineLimit(1)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding(RigLibrarySidebarView.rowPadding)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: RigLibrarySidebarView.rowCorner)
|
|
.fill(Color.orange.opacity(isSelected ? RigLibrarySidebarView.selectedOpacity : 0))
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.contextMenu {
|
|
Button("Rename…") { onRename(entry) }
|
|
Button("Duplicate…") { onDuplicate(entry) }
|
|
Divider()
|
|
Button("Delete", role: .destructive) { onDelete(entry) }
|
|
}
|
|
}
|
|
|
|
// MARK: - Action bar
|
|
|
|
private var actionBar: some View {
|
|
HStack(spacing: 6) {
|
|
Button { onNew() } label: { Image(systemName: "plus") }
|
|
.help("New rig")
|
|
Button { onSave() } label: { Image(systemName: "square.and.arrow.down") }
|
|
.help("Save the current rig")
|
|
Button { onSaveAs() } label: { Image(systemName: "doc.on.doc") }
|
|
.help("Save the current rig as a new entry")
|
|
Spacer()
|
|
Menu {
|
|
Button("Import Archive…") { onImportArchive() }
|
|
Button("Export Archive…") { onExportArchive() }
|
|
Divider()
|
|
Button("Erase All Rigs…", role: .destructive) { onEraseAll() }
|
|
} label: {
|
|
Image(systemName: "ellipsis.circle")
|
|
}
|
|
.menuStyle(.borderlessButton)
|
|
.fixedSize()
|
|
.help("Archive and library options")
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.tint(.orange)
|
|
.padding(.top, 2)
|
|
}
|
|
}
|