diff --git a/frontend/src-tauri/gen/apple/Haystack/ShareViewController.swift b/frontend/src-tauri/gen/apple/Haystack/ShareViewController.swift index dc8a410..c102aef 100644 --- a/frontend/src-tauri/gen/apple/Haystack/ShareViewController.swift +++ b/frontend/src-tauri/gen/apple/Haystack/ShareViewController.swift @@ -7,24 +7,97 @@ import UIKit import Social +import MobileCoreServices class ShareViewController: SLComposeServiceViewController { + let appGroupName = "group.com.haystack.app" // Replace with your actual App Group identifier + let tokenKey = "sharedAuthToken" + let uploadURL = URL(string: "http://192.168.1.199:3040/image/")! + + var bearerToken: String? + + override func viewDidLoad() { + super.viewDidLoad() + + // Load the bearer token from the App Group + if let sharedDefaults = UserDefaults(suiteName: appGroupName) { + bearerToken = sharedDefaults.string(forKey: tokenKey) + print("Retrieved bearer token: \(bearerToken ?? "nil")") + } else { + print("Error accessing App Group UserDefaults.") + } + + if let item = extensionContext?.inputItems.first as? NSExtensionItem, + let provider = item.attachments?.first as? NSItemProvider { + if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { + let semaphore = DispatchSemaphore(value: 0) + var rawImageData: Data? + var extractedName = "image.png" // Default name + + provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { [weak self] (item, error) in + guard let self = self else { + semaphore.signal() + return + } + if let url = item as? URL, let data = try? Data(contentsOf: url) { + rawImageData = data + extractedName = url.lastPathComponent + if let dotRange = extractedName.range(of: ".", options: .backwards) { + extractedName = String(extractedName[.. Bool { - // Do validation of contentText and/or NSExtensionContext attachments here - return true + return true // Always valid for now } override func didSelectPost() { - // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. - - // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. - self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil) + // The upload happens in uploadRawData after the data is loaded } override func configurationItems() -> [Any]! { - // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. return [] } - }