MacOS Damus Support allowing link and photo sharing option

Changelog-Fixed: Fixed link and photo sharing support on macOS
Signed-off-by: Swift Coder <scoder1747@gmail.com>
This commit is contained in:
Swift Coder
2024-12-18 09:17:53 -05:00
committed by Daniel D’Aquino
parent 4cf8097de4
commit 54ea1ab803

View File

@@ -309,8 +309,27 @@ struct ShareExtensionView: View {
} }
} else if itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) { } else if itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { (item, error) in itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { (item, error) in
// Sharing URLs from iPhone/Safari to Damus also follows this pathway
// Sharing Photos or Links from macOS/Finder or macOS/Safari to Damus sets item-provider conforming to UTType.url.identifier and therefore takes this pathway
if let url = item as? URL { if let url = item as? URL {
// Sharing Photos from macOS/Finder
if url.absoluteString.hasPrefix("file:///") {
attemptAcquireResourceAndChooseMedia(
url: url,
fallback: processImage,
unprocessedEnum: {.unprocessed_image($0)},
processedEnum: {.processed_image($0)})
} else {
// Sharing URLs from iPhone/Safari to Damus
self.share_state = .loaded(ShareContent(title: title, content: .link(url))) self.share_state = .loaded(ShareContent(title: title, content: .link(url)))
}
} else if let data = item as? Data,
let string = String(data: data, encoding: .utf8),
let url = URL(string: string) {
// Sharing Links from macOS/Safari, does not provide title
self.share_state = .loaded(ShareContent(title: "", content: .link(url)))
} else { } else {
self.share_state = .failed(error: "Failed to load text content") self.share_state = .failed(error: "Failed to load text content")
} }