diff --git a/Demo/ShoeGazeBuilder/AppDelegate.swift b/Demo/ShoeGazeBuilder/AppDelegate.swift
index d7be091..2d61830 100644
--- a/Demo/ShoeGazeBuilder/AppDelegate.swift
+++ b/Demo/ShoeGazeBuilder/AppDelegate.swift
@@ -154,6 +154,57 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
true
}
+ /// Opens `.shoegaze` files handed to the app by Finder, AirDrop, "Open With", or a double-click.
+ ///
+ /// Rig documents are imported into the library (they appear in the sidebar, ready to load);
+ /// board documents are surfaced with a note that boards are opened from a rig's board editor.
+ func application(_ application: NSApplication, open urls: [URL]) {
+ for url: URL in urls {
+ openShoeGazeDocument(at: url)
+ }
+ }
+
+ /// Reads and imports a single `.shoegaze` document, reporting the outcome to the user.
+ private func openShoeGazeDocument(at url: URL) {
+ // A LaunchServices-supplied URL is security-scoped; start access to read it.
+ let scoped: Bool = url.startAccessingSecurityScopedResource()
+ defer { if scoped { url.stopAccessingSecurityScopedResource() } }
+ do {
+ let data: Data = try Data(contentsOf: url)
+ let document: ShoeGazeDocument = try ShoeGazeDocument.decoded(from: data)
+ if document.rigEntries?.isEmpty == false {
+ let added: Int = try library.importArchive(from: data)
+ presentOpenInfo(
+ title: added == 1 ? "Rig Imported" : "Rigs Imported",
+ message: added == 1
+ ? "Added 1 rig to your library. Select it in the Rigs sidebar to load it."
+ : "Added \(added) rigs to your library. Select one in the Rigs sidebar to load it."
+ )
+ } else if document.boardVersion != nil {
+ presentOpenInfo(
+ title: "Board Document",
+ message: "This file is a single board. Open a rig, then load the board from the "
+ + "board editor's Versions menu."
+ )
+ }
+ } catch {
+ presentOpenInfo(
+ title: "Couldn’t Open File",
+ message: "“\(url.lastPathComponent)” is not a readable ShoeGaze document."
+ )
+ print("[ShoeGazeBuilder] open document failed: \(error)")
+ }
+ }
+
+ /// Shows a one-button informational alert for a document-open outcome.
+ private func presentOpenInfo(title: String, message: String) {
+ let alert: NSAlert = NSAlert()
+ alert.messageText = title
+ alert.informativeText = message
+ alert.addButton(withTitle: "OK")
+ alert.runModal()
+ }
+
func applicationWillTerminate(_ notification: Notification) {
RigStore.save(shoeGaze)
// Ensure any in-flight background rig-library writes finish before exit.
@@ -267,20 +318,22 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
@objc private func exportArchiveAction(_ sender: Any?) {
let panel: NSSavePanel = NSSavePanel()
- panel.allowedContentTypes = [.json]
- panel.nameFieldStringValue = "\(AppDelegate.defaultArchiveFileName).json"
+ panel.allowedContentTypes = [.shoeGaze]
+ panel.nameFieldStringValue =
+ "\(AppDelegate.defaultArchiveFileName).\(ShoeGazeDocument.fileExtension)"
panel.canCreateDirectories = true
let rigLibrary: RigLibraryStore = library
panel.begin { response in
guard response == .OK, let url: URL = panel.url else { return }
- do { try rigLibrary.exportArchiveData().write(to: url, options: .atomic) }
- catch { print("[ShoeGazeBuilder] export archive failed: \(error)") }
+ do { try rigLibrary.exportDocumentData().write(to: url, options: .atomic) }
+ catch { print("[ShoeGazeBuilder] export library failed: \(error)") }
}
}
@objc private func importArchiveAction(_ sender: Any?) {
let panel: NSOpenPanel = NSOpenPanel()
- panel.allowedContentTypes = [.json]
+ // Accept the .shoegaze document plus legacy plain-JSON archives.
+ panel.allowedContentTypes = [.shoeGaze, .json]
panel.canChooseDirectories = false
panel.allowsMultipleSelection = false
let rigLibrary: RigLibraryStore = library
@@ -290,7 +343,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let data: Data = try Data(contentsOf: url)
_ = try rigLibrary.importArchive(from: data)
} catch {
- print("[ShoeGazeBuilder] import archive failed: \(error)")
+ print("[ShoeGazeBuilder] import library failed: \(error)")
}
}
}
diff --git a/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSApp.swift b/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSApp.swift
index e3b2479..2fadaf9 100644
--- a/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSApp.swift
+++ b/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSApp.swift
@@ -35,6 +35,7 @@ struct ShoeGazeBuilderiOSApp: App {
.task { await model.startLibrary() }
}
.onDisappear { model.stop() }
+ .onOpenURL { url in model.importDocument(at: url) }
}
.onChange(of: scenePhase) { _, phase in
// Persist the rig whenever the app leaves the foreground.
diff --git a/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSAppModel.swift b/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSAppModel.swift
index 2899ef4..644b65f 100644
--- a/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSAppModel.swift
+++ b/Demo/ShoeGazeBuilderiOS/ShoeGazeBuilderiOSAppModel.swift
@@ -93,6 +93,25 @@ final class ShoeGazeBuilderiOSAppModel {
library.flushPendingWrites()
}
+ // MARK: - Document open
+
+ /// Imports a `.shoegaze` file opened from Files, AirDrop, or another app into the rig library.
+ /// Rig documents add their rigs (they appear in the sidebar, ready to load); board documents are
+ /// ignored here. Returns the number of rigs added.
+ @discardableResult
+ func importDocument(at url: URL) -> Int {
+ // A document opened from outside the sandbox is security-scoped; start access to read it.
+ let scoped: Bool = url.startAccessingSecurityScopedResource()
+ defer { if scoped { url.stopAccessingSecurityScopedResource() } }
+ do {
+ let data: Data = try Data(contentsOf: url)
+ return try library.importArchive(from: data)
+ } catch {
+ print("[ShoeGazeBuilderiOS] open document failed: \(error)")
+ return 0
+ }
+ }
+
// MARK: - Audio session / engine construction
/// Activates the play-and-record audio session once. Idempotent; safe to call before each
diff --git a/Demo/ShoeGazeDemo/Info.plist b/Demo/ShoeGazeDemo/Info.plist
index 61361cd..d23e0ba 100644
--- a/Demo/ShoeGazeDemo/Info.plist
+++ b/Demo/ShoeGazeDemo/Info.plist
@@ -28,44 +28,5 @@
ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.
NSPrincipalClass
NSApplication
- CFBundleDocumentTypes
-
-
- CFBundleTypeName
- ShoeGaze Document
- CFBundleTypeRole
- Editor
- LSHandlerRank
- Owner
- LSItemContentTypes
-
- net.realizedsound.shoegaze
-
-
-
- UTExportedTypeDeclarations
-
-
- UTTypeIdentifier
- net.realizedsound.shoegaze
- UTTypeDescription
- ShoeGaze Document
- UTTypeConformsTo
-
- public.json
-
- UTTypeTagSpecification
-
- public.filename-extension
-
- shoegaze
-
- public.mime-type
-
- application/json
-
-
-
-
diff --git a/Demo/ShoeGazeiOSDemo/Info.plist b/Demo/ShoeGazeiOSDemo/Info.plist
index e73fcd5..6723281 100644
--- a/Demo/ShoeGazeiOSDemo/Info.plist
+++ b/Demo/ShoeGazeiOSDemo/Info.plist
@@ -41,44 +41,5 @@
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
- CFBundleDocumentTypes
-
-
- CFBundleTypeName
- ShoeGaze Document
- CFBundleTypeRole
- Editor
- LSHandlerRank
- Owner
- LSItemContentTypes
-
- net.realizedsound.shoegaze
-
-
-
- UTExportedTypeDeclarations
-
-
- UTTypeIdentifier
- net.realizedsound.shoegaze
- UTTypeDescription
- ShoeGaze Document
- UTTypeConformsTo
-
- public.json
-
- UTTypeTagSpecification
-
- public.filename-extension
-
- shoegaze
-
- public.mime-type
-
- application/json
-
-
-
-