Open .shoegaze files: wire document handlers, scope type to builders
Registering the document type made the apps claim .shoegaze, but without an open handler macOS reported "cannot open files in the ShoeGaze Document format." Wire actual opening: - macOS Builder: implement application(_:open:) — decode the document and import its rigs into the library (board files get an explanatory note), with a confirmation alert. Also migrate the File-menu Export/Import panels to .shoegaze (still importing legacy JSON). - iOS Builder: add .onOpenURL and an importDocument(at:) on the app model. - Drop the document-type declaration from the two minimal player demos (ShoeGazeDemo, ShoeGazeiOSDemo); they have no open/share UI, so only the two Builder apps should claim the type. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,44 +28,5 @@
|
||||
<string>ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>UTExportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.json</string>
|
||||
</array>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
<array>
|
||||
<string>shoegaze</string>
|
||||
</array>
|
||||
<key>public.mime-type</key>
|
||||
<array>
|
||||
<string>application/json</string>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -41,44 +41,5 @@
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>UTExportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>net.realizedsound.shoegaze</string>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>ShoeGaze Document</string>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.json</string>
|
||||
</array>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
<array>
|
||||
<string>shoegaze</string>
|
||||
</array>
|
||||
<key>public.mime-type</key>
|
||||
<array>
|
||||
<string>application/json</string>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
Reference in New Issue
Block a user