// // Attachments.swift // QuickDrop // // Created by Leon Böttger on 17.08.25. // import Foundation import UniformTypeIdentifiers import SwiftUI #if os(macOS) import Cocoa #endif func loadAttachments(with extensionContext: NSExtensionContext?, loadedItems: @escaping (AttachmentDetails) -> Void) { guard let extensionContext = extensionContext else { fatalError() } log("Loading attachments...") var result = AttachmentDetails(urls: [], textToSend: nil, shortDescription: "", previewImage: nil) var ignoredAttachments = 0 let item = extensionContext.inputItems[0] as! NSExtensionItem if let attachments = item.attachments { if let text = item.attributedContentText?.string { log("Found text content: \(text)") result.textToSend = text #if os(macOS) result.previewImage = NSImage(named: NSImage.multipleDocumentsName) #else result.previewImage = Image(systemName: "text.document") #endif let maxLength = 50 let cleanedText = text.replacingOccurrences(of: "\n", with: " ").replacingOccurrences(of: "\r", with: "") if cleanedText.count > maxLength { let index = cleanedText.index(cleanedText.startIndex, offsetBy: maxLength) result.shortDescription = String(cleanedText[..