Add .shoegaze document type and rig/board sharing
Introduce a single shareable document type for rigs and boards: - ShoeGazeDocument: versioned JSON envelope wrapping either a RigArchive (one or many rigs) or a BoardVersion, with a tolerant decoder that also reads the legacy bare-RigArchive and bare-ShoeGazeState shapes. - Register the .shoegaze UTType (net.realizedsound.shoegaze, conforms to public.json) in all four demo app Info.plists. - Migrate library export/import onto the envelope: exportDocumentData() and a decoder-tolerant importArchive(); RigFileDocument and the Builder exporter/importer now use .shoegaze. Internal per-rig and board-version files stay app-private JSON. - Add OS share-sheet entries via SwiftUI ShareLink: Share per rig in the library sidebar, Share per version in the board editor, backed by the Transferable wrappers RigShareItem / BoardShareItem. Tests: ShoeGazeDocument round-trip and legacy decode, library .shoegaze export/import round-trip, and a board-document-imports-no-rigs case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -278,22 +278,39 @@ public final class RigLibraryStore {
|
||||
|
||||
// MARK: - Archive import / export
|
||||
|
||||
/// Encodes the entire library as a single ``RigArchive`` JSON document for export.
|
||||
/// Encodes the entire library as a single ``RigArchive`` JSON document.
|
||||
///
|
||||
/// - Returns: Pretty-printed archive bytes suitable for a `fileExporter` / `NSSavePanel`.
|
||||
/// Retained for callers and tests that want the bare archive bytes. The user-facing
|
||||
/// export/share path uses ``exportDocumentData()``, which wraps the same rigs in a
|
||||
/// ``ShoeGazeDocument`` envelope (the `.shoegaze` file type).
|
||||
///
|
||||
/// - Returns: Pretty-printed archive bytes.
|
||||
/// - Throws: `JSONEncoder` errors.
|
||||
public func exportArchiveData() throws -> Data {
|
||||
let archive: RigArchive = RigArchive(rigs: entries)
|
||||
return try RigLibraryStore.makeEncoder().encode(archive)
|
||||
}
|
||||
|
||||
/// Encodes the entire library as a ``ShoeGazeDocument`` for export to a `.shoegaze` file.
|
||||
///
|
||||
/// This is the format written by the library's **Export** action and shared via the system
|
||||
/// share sheet. ``importArchive(from:)`` reads it back, and also still accepts the bare
|
||||
/// ``RigArchive`` and legacy single-rig shapes.
|
||||
///
|
||||
/// - Returns: Pretty-printed `.shoegaze` document bytes.
|
||||
/// - Throws: `JSONEncoder` errors.
|
||||
public func exportDocumentData() throws -> Data {
|
||||
try ShoeGazeDocument(rigs: entries).data()
|
||||
}
|
||||
|
||||
/// Imports rigs from archive `data`, saving each into the library, and returns how many were
|
||||
/// added.
|
||||
///
|
||||
/// Accepts either a ``RigArchive`` (the multi-rig export format) or a legacy single-rig file
|
||||
/// (a bare ``ShoeGazeState``), which is imported as one entry named `legacyRigName`. Imported
|
||||
/// entries whose `id` already exists in the library are given a fresh `id` so an import never
|
||||
/// silently overwrites an existing rig.
|
||||
/// Accepts a ``ShoeGazeDocument`` (the `.shoegaze` file type), a bare ``RigArchive`` (the prior
|
||||
/// multi-rig export), or a legacy single-rig file (a bare ``ShoeGazeState``), which is imported
|
||||
/// as one entry named `legacyRigName`. A document carrying a board rather than rigs contributes
|
||||
/// no entries. Imported entries whose `id` already exists in the library are given a fresh `id`
|
||||
/// so an import never silently overwrites an existing rig.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - data: Archive or legacy-rig JSON bytes.
|
||||
@@ -512,19 +529,15 @@ public final class RigLibraryStore {
|
||||
return decoder
|
||||
}
|
||||
|
||||
/// Decodes import bytes as a ``RigArchive`` first, falling back to a legacy single-rig
|
||||
/// ``ShoeGazeState``.
|
||||
/// Decodes import bytes into rig entries, accepting the `.shoegaze` ``ShoeGazeDocument``
|
||||
/// envelope plus the bare ``RigArchive`` and legacy ``ShoeGazeState`` shapes (see
|
||||
/// ``ShoeGazeDocument/decoded(from:legacyRigName:)``). A board-carrying document yields no rigs.
|
||||
private func decodeImportable(
|
||||
_ data: Data,
|
||||
legacyRigName: String
|
||||
) throws -> [RigEntry] {
|
||||
let decoder: JSONDecoder = RigLibraryStore.makeDecoder()
|
||||
if let archive: RigArchive = try? decoder.decode(RigArchive.self, from: data) {
|
||||
return archive.rigs
|
||||
}
|
||||
// A legacy single-rig file is a bare ShoeGazeState (no `rigs` array). Decode and wrap.
|
||||
let state: ShoeGazeState = try decoder.decode(ShoeGazeState.self, from: data)
|
||||
return [RigEntry(name: legacyRigName, state: state)]
|
||||
let document: ShoeGazeDocument = try ShoeGazeDocument.decoded(from: data, legacyRigName: legacyRigName)
|
||||
return document.rigEntries ?? []
|
||||
}
|
||||
|
||||
// MARK: - In-memory helpers
|
||||
|
||||
Reference in New Issue
Block a user