aeab19236b
ShareLink with a DataRepresentation hands the share sheet raw bytes, which on macOS collapses the menu to just Copy / Edit Extensions — AirDrop, Messages, Mail, and Notes only appear for an actual file on disk. Switch RigShareItem / BoardShareItem to FileRepresentation: write the encoded .shoegaze document to a unique temporary file when a destination is picked, and hand its URL to the share sheet. Extract the shared temp-file writer alongside shareFilenameBase. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
// BoardShareItem.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
import CoreTransferable
|
|
import UniformTypeIdentifiers
|
|
import LyrebirdShoeGaze
|
|
|
|
/// A `Transferable` wrapper that lets a `ShareLink` send a single board as a `.shoegaze` document.
|
|
///
|
|
/// Mirrors ``RigShareItem`` for a board snapshot: it holds the already-encoded document bytes and,
|
|
/// via `FileRepresentation`, writes them to a temporary `<board>.shoegaze` file when a share
|
|
/// destination is picked — giving the share sheet a real file so AirDrop, Messages, Mail, Notes,
|
|
/// and Files all appear (raw data collapses the macOS menu to Copy / Edit Extensions).
|
|
struct BoardShareItem: Transferable, Sendable {
|
|
|
|
/// Filesystem-safe base name for the shared file (no extension).
|
|
let filenameBase: String
|
|
|
|
/// Encoded `.shoegaze` document bytes.
|
|
let data: Data
|
|
|
|
/// Encodes `version` as a single-board `.shoegaze` document.
|
|
///
|
|
/// - Parameter version: The board snapshot to share.
|
|
/// - Throws: Any `JSONEncoder` error from ``ShoeGazeDocument/data()``.
|
|
init(board version: BoardVersion) throws {
|
|
self.filenameBase = shareFilenameBase(version.name)
|
|
self.data = try ShoeGazeDocument(board: version).data()
|
|
}
|
|
|
|
static var transferRepresentation: some TransferRepresentation {
|
|
FileRepresentation(exportedContentType: .shoeGaze) { item in
|
|
SentTransferredFile(try writeShoeGazeShareFile(item.data, base: item.filenameBase))
|
|
}
|
|
.suggestedFileName { item in
|
|
"\(item.filenameBase).\(ShoeGazeDocument.fileExtension)"
|
|
}
|
|
}
|
|
}
|