From aeab19236b74bc12dc150232f43c7b8d1f2bc454 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Sun, 28 Jun 2026 18:03:13 -0700 Subject: [PATCH] Share a real file so the macOS share sheet offers full services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../LyrebirdShoeGazeUI/BoardShareItem.swift | 11 ++++---- Sources/LyrebirdShoeGazeUI/RigShareItem.swift | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Sources/LyrebirdShoeGazeUI/BoardShareItem.swift b/Sources/LyrebirdShoeGazeUI/BoardShareItem.swift index abdcc6d..dfbc072 100644 --- a/Sources/LyrebirdShoeGazeUI/BoardShareItem.swift +++ b/Sources/LyrebirdShoeGazeUI/BoardShareItem.swift @@ -11,9 +11,10 @@ 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 -/// the system serialises them to a temporary `.shoegaze` file for AirDrop, Mail, Messages, -/// and Files. +/// Mirrors ``RigShareItem`` for a board snapshot: it holds the already-encoded document bytes and, +/// via `FileRepresentation`, writes them to a temporary `.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). @@ -32,8 +33,8 @@ struct BoardShareItem: Transferable, Sendable { } static var transferRepresentation: some TransferRepresentation { - DataRepresentation(exportedContentType: .shoeGaze) { item in - item.data + FileRepresentation(exportedContentType: .shoeGaze) { item in + SentTransferredFile(try writeShoeGazeShareFile(item.data, base: item.filenameBase)) } .suggestedFileName { item in "\(item.filenameBase).\(ShoeGazeDocument.fileExtension)" diff --git a/Sources/LyrebirdShoeGazeUI/RigShareItem.swift b/Sources/LyrebirdShoeGazeUI/RigShareItem.swift index 4563361..43984a4 100644 --- a/Sources/LyrebirdShoeGazeUI/RigShareItem.swift +++ b/Sources/LyrebirdShoeGazeUI/RigShareItem.swift @@ -13,8 +13,12 @@ import LyrebirdShoeGaze /// /// Holds the already-encoded document bytes (a value type, so the wrapper is `Sendable` as /// `Transferable` requires). The encode happens when the share menu is built for the focused row — -/// cheap, one rig — via the throwing ``init(rig:)``. The system serialises the bytes to a temporary -/// file named `.shoegaze` for AirDrop, Mail, Messages, and Files. +/// cheap, one rig — via the throwing ``init(rig:)``. +/// +/// Uses `FileRepresentation` (not `DataRepresentation`): the share sheet — AirDrop, Messages, +/// Mail, Notes, Files — only offers its full service list when handed a real file on disk. The +/// bytes are written to a temporary `.shoegaze` when a destination is picked. Sharing raw +/// data instead collapses the macOS menu to just Copy / Edit Extensions. struct RigShareItem: Transferable, Sendable { /// Filesystem-safe base name for the shared file (no extension). @@ -33,8 +37,8 @@ struct RigShareItem: Transferable, Sendable { } static var transferRepresentation: some TransferRepresentation { - DataRepresentation(exportedContentType: .shoeGaze) { item in - item.data + FileRepresentation(exportedContentType: .shoeGaze) { item in + SentTransferredFile(try writeShoeGazeShareFile(item.data, base: item.filenameBase)) } .suggestedFileName { item in "\(item.filenameBase).\(ShoeGazeDocument.fileExtension)" @@ -54,3 +58,17 @@ func shareFilenameBase(_ name: String) -> String { let trimmed: String = mapped.trimmingCharacters(in: CharacterSet(charactersIn: "_")) return trimmed.isEmpty ? "ShoeGaze" : trimmed } + +/// Writes `data` to a uniquely-named temporary `.shoegaze` file and returns its URL, for a +/// `FileRepresentation` to hand the share sheet a real file. A fresh per-share subdirectory avoids +/// collisions when the same name is shared twice. Shared by ``RigShareItem`` and ``BoardShareItem``. +func writeShoeGazeShareFile(_ data: Data, base: String) throws -> URL { + let directory: URL = FileManager.default.temporaryDirectory + .appendingPathComponent("ShoeGazeShare-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) + let url: URL = directory + .appendingPathComponent(base) + .appendingPathExtension(ShoeGazeDocument.fileExtension) + try data.write(to: url, options: .atomic) + return url +}