Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Share Extension] Support images/movies from other apps like iMessage (#5515)

authored by

Hailey and committed by
GitHub
dd1944e9 77c4a992

+39 -3
+39 -3
modules/Share-with-Bluesky/ShareViewController.swift
··· 1 1 import UIKit 2 2 3 + let IMAGE_EXTENSIONS: [String] = ["png", "jpg", "jpeg", "gif", "heic"] 4 + let MOVIE_EXTENSIONS: [String] = ["mov", "mp4", "m4v"] 5 + 6 + enum URLType: String, CaseIterable { 7 + case image 8 + case movie 9 + case other 10 + } 11 + 3 12 class ShareViewController: UIViewController { 4 13 // This allows other forks to use this extension while also changing their 5 14 // scheme. ··· 43 52 44 53 private func handleUrl(item: NSItemProvider) async { 45 54 if let data = try? await item.loadItem(forTypeIdentifier: "public.url") as? URL { 46 - if let encoded = data.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed), 47 - let url = URL(string: "\(self.appScheme)://intent/compose?text=\(encoded)") { 48 - _ = self.openURL(url) 55 + switch data.type { 56 + case .image: 57 + await handleImages(items: [item]) 58 + return 59 + case .movie: 60 + await handleVideos(items: [item]) 61 + return 62 + case .other: 63 + if let encoded = data.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed), 64 + let url = URL(string: "\(self.appScheme)://intent/compose?text=\(encoded)") { 65 + _ = self.openURL(url) 66 + } 49 67 } 50 68 } 51 69 self.completeRequest() ··· 158 176 return false 159 177 } 160 178 } 179 + 180 + extension URL { 181 + var type: URLType { 182 + get { 183 + guard self.absoluteString.starts(with: "file://"), 184 + let ext = self.pathComponents.last?.split(separator: ".").last?.lowercased() else { 185 + return .other 186 + } 187 + 188 + if IMAGE_EXTENSIONS.contains(ext) { 189 + return .image 190 + } else if MOVIE_EXTENSIONS.contains(ext) { 191 + return .movie 192 + } 193 + return .other 194 + } 195 + } 196 + }