From a9749f062e637ce2c90d20cf4ba4a01d5c94f94e Mon Sep 17 00:00:00 2001 From: Rio Keefe Date: Sat, 10 May 2025 22:18:49 +0100 Subject: [PATCH] feat: setting up a different share extension idk what happened to the old one --- .DS_Store | Bin 6148 -> 8196 bytes frontend/.DS_Store | Bin 0 -> 6148 bytes frontend/src-tauri/.DS_Store | Bin 0 -> 6148 bytes frontend/src-tauri/gen/apple/.DS_Store | Bin 0 -> 6148 bytes .../gen/apple/Haystack Sharing/.DS_Store | Bin 0 -> 6148 bytes .../apple/Haystack.xcodeproj/project.pbxproj | 90 +++++---- .../Base.lproj/MainInterface.storyboard | 24 +++ .../src-tauri/gen/apple/Sharing/Info.plist | 31 ++++ .../apple/Sharing/ShareViewController.swift | 172 ++++++++++++++++++ .../apple/Sharing/Sharingdebug.entitlements | 10 + .../apple/Sharing/Sharingrelease.entitlements | 10 + frontend/src-tauri/tauri.conf.json | 5 +- 12 files changed, 295 insertions(+), 47 deletions(-) create mode 100644 frontend/.DS_Store create mode 100644 frontend/src-tauri/.DS_Store create mode 100644 frontend/src-tauri/gen/apple/.DS_Store create mode 100644 frontend/src-tauri/gen/apple/Haystack Sharing/.DS_Store create mode 100644 frontend/src-tauri/gen/apple/Sharing/Base.lproj/MainInterface.storyboard create mode 100644 frontend/src-tauri/gen/apple/Sharing/Info.plist create mode 100644 frontend/src-tauri/gen/apple/Sharing/ShareViewController.swift create mode 100644 frontend/src-tauri/gen/apple/Sharing/Sharingdebug.entitlements create mode 100644 frontend/src-tauri/gen/apple/Sharing/Sharingrelease.entitlements diff --git a/.DS_Store b/.DS_Store index 7b264ca014ca6bbc6c53c2ca16e5bab8fe23139f..d0efd2c12f0635a3502d41665f3a7c2a89fc57ae 100644 GIT binary patch delta 323 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$h$FMH}hr%jz7$c**Q2SHn1@A zZsuW`$2hr$m7gc6ytp7KCqD_OVaMbumcmqt>S`l1104k;Ba2!cg=$M9AluZ`ytbB; zLsVJcIw(FnCpRy@3#c9l7#Sfn122?@QQbfWJ3|sfB11AmHbW{y9z#l5a8X`PeqK6I zhH>(8)(Q-(-Kk{tWNx*tkI|qj#Gf*WE2yg=lSCFQSh2NPc^UHXGj9_4b7zeU}VRJms9A*HYsT1@7 diff --git a/frontend/.DS_Store b/frontend/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8c1bdf7d3cb753ee0e97636c7ef54f200688edf5 GIT binary patch literal 6148 zcmeHKO>fgM7=GQBE#25u5J_BRAIE+l$A0|Au8BzWv(W>h77;l}jEx;+ml(HmTC?iJ2{C40K!*@)dF`5%f>71ep=WB&?9So^B19)>O!#u{6RCvGE zcvJFuw?aOFf16G*LP>F%SDRFLH)skk%mv&8zcvso`h>AhbT8!|lz!g|`fZ_y3>rpY z3@g5@T+z3VH_WPDO1Gj{Q+v@pjLJvfGYZT73Rdk3Mvx~{vxYx{X%r@Dr}I

Wyn# z+s?ML>wNG|WbUPYnk9XI_Ku%kOBn^LvLCz&$N8Xj>$!|mKa9sSMF>Y@xV(QG#v_^c zWfqST#r1T9({!4H*1>$+`fDN>8rt6bRNqum<3GW zv{ANaa0NWeOSHJ~W^p8AUP)%&R4RqgKR5Aq75J|d5RGH+xQ{8BvvqB9eAc>1 sACcJDZ>dpHkeTCH75FGVKvIS_mkYq2!KFsj!0aCZC49YxoC# zfh}Lczp#RHXC}gSC@X{znk(Horg-?#gtI(`wbEqppG|&hw#Ji%8(JvgO_gn^pl26R(TZgyE{zQq`P?Y*C7361UJQp{ zMW@@_+TL+?oIU52|5h&iVp^2>c$&T7r>9aT!8$(;p2g8(GPr&s(_$K@QKks-EJDc3 z=W#ldi?J-zS+2Ogu5kKJe=^u#E=PBV2kvNeygG1~_eaPd9o<{4`p%78w;w#2oF^Bl z{DASp1a^64R}HR#SD-Qf_kNZpGG!&1b4_VeLd6&>uT_78+&d_X6=s~DW zSq02$I=ly1vkF)RtO9ifczb%7 literal 0 HcmV?d00001 diff --git a/frontend/src-tauri/gen/apple/.DS_Store b/frontend/src-tauri/gen/apple/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..512abb9ec99ebd3f52f7c34352dd47a0d1ec9d49 GIT binary patch literal 6148 zcmeHK%SyyR5UkccEO^P$xFYWzFEjo< zb9+2s#O`g_k5A9zF7G*hkg`%h3P=GdAO)nruN3g!OIx2MDoOz!2`1J0?au=EmFcc@$+`^EIFMg;QeCnGZTqKLf6dObYz90$+~x7cu|< literal 0 HcmV?d00001 diff --git a/frontend/src-tauri/gen/apple/Haystack Sharing/.DS_Store b/frontend/src-tauri/gen/apple/Haystack Sharing/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..aa19317cea46035fb01e04a6dcb7b961d684104f GIT binary patch literal 6148 zcmeHKu};G<5PdEkN?AI>faHNW5`Pdvk?35B8Cnb!0zpX-V$06Q@QLuwwjz?iicobY zou7U7J0~wzYy&Xa%k?oZ12CZrj&@o6VA3x>uu+VRiN@zhkmDI83fvDyYv4aBAm46^ z3|FY&@a_98@?yQpixvB2ah%YTPj9RNM>r?vjjWou#se&txMRJ<22Z#pI<5xSW_FC$ z?5lnBkv-C`dh>kr=9yx_aW`C130GE5K4tNxp07N-P zdShLVi^8!H(}+z#_RvhA5(Cx5D~1Vl#%&yzMr;BGI!wHLm^ibEHx%P%XMXF4!=wSV zR0ULlt^zxuIg|bW?DzYBm!vIKKo!_31 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/src-tauri/gen/apple/Sharing/Info.plist b/frontend/src-tauri/gen/apple/Sharing/Info.plist new file mode 100644 index 0000000..8420861 --- /dev/null +++ b/frontend/src-tauri/gen/apple/Sharing/Info.plist @@ -0,0 +1,31 @@ + + + + + NSExtension + + NSExtensionAttributes + + NSExtensionActivationRule + + NSExtensionActivationSupportsImageWithMaxCount + 1 + NSExtensionActivationSupportsMovieWithMaxCount + 0 + NSExtensionActivationSupportsFileWithMaxCount + 0 + NSExtensionActivationSupportsText + + NSExtensionActivationSupportsWebURLWithMaxCount + 0 + NSExtensionActivationSupportsWebPageWithMaxCount + 0 + + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.share-services + + + diff --git a/frontend/src-tauri/gen/apple/Sharing/ShareViewController.swift b/frontend/src-tauri/gen/apple/Sharing/ShareViewController.swift new file mode 100644 index 0000000..28e93bd --- /dev/null +++ b/frontend/src-tauri/gen/apple/Sharing/ShareViewController.swift @@ -0,0 +1,172 @@ +// +// +//  ShareViewController.swift +//  Haystack +// +//  Created by Rio Keefe on 03/05/2025. +// + +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: "https://haystack.johncosta.tech/image/")! + + var bearerToken: String? + // Store the item provider to access it later in didSelectPost + private var imageItemProvider: NSItemProvider? + private var extractedImageName: String = "image" // Default name + + override func viewDidLoad() { + super.viewDidLoad() + + // Load the bearer token from the App Group in viewDidLoad + // This is okay as reading from UserDefaults is fast + if let sharedDefaults = UserDefaults(suiteName: appGroupName) { + bearerToken = sharedDefaults.string(forKey: tokenKey) + print("Retrieved bearer token: \(bearerToken ?? "nil")") + } else { + print("Error accessing App Group UserDefaults.") + // Optionally inform the user or disable posting if token is crucial + // self.isContentValid() could check if bearerToken is nil + } + + // Store the item provider, but don't load the data synchronously yet + if let item = extensionContext?.inputItems.first as? NSExtensionItem, + let provider = item.attachments?.first as? NSItemProvider { + if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) { + self.imageItemProvider = provider + // Attempt to get a suggested name early if available + extractedImageName = provider.suggestedName ?? "image" + if let dotRange = extractedImageName.range(of: ".", options: .backwards) { + extractedImageName = String(extractedImageName[.. Bool { + // Content is valid only if we have an item provider for an image AND a bearer token + return imageItemProvider != nil && bearerToken != nil + } + + override func didSelectPost() { + // This method is called when the user taps the "Post" button. + // Start the asynchronous operation here. + + guard let provider = imageItemProvider else { + print("Error: No image item provider found when posting.") + // Inform the user or log an error + extensionContext!.completeRequest(returningItems: [], completionHandler: nil) + return + } + + guard let token = bearerToken else { + print("Error: Bearer token is missing when posting.") + // Inform the user or log an error + extensionContext!.completeRequest(returningItems: [], completionHandler: nil) + return + } + + // Load the image data asynchronously + provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil) { [weak self] (item, error) in + guard let self = self else { return } + + if let error = error { + print("Error loading image data for upload: \(error.localizedDescription)") + // Inform the user about the failure + self.extensionContext!.cancelRequest(withError: error) + return + } + + var rawImageData: Data? + var finalImageName = self.extractedImageName // Use the name extracted earlier + + if let url = item as? URL, let data = try? Data(contentsOf: url) { + rawImageData = data + // Refine the name extraction here if necessary, though doing it in viewDidLoad is also an option + finalImageName = url.lastPathComponent + if let dotRange = finalImageName.range(of: ".", options: .backwards) { + finalImageName = String(finalImageName[.. [Any]! { + // You can add items here if you want to allow the user to enter additional info + // e.g., a text field for a caption. + // This example only handles image upload, so no config items are needed. + return [] + } +} diff --git a/frontend/src-tauri/gen/apple/Sharing/Sharingdebug.entitlements b/frontend/src-tauri/gen/apple/Sharing/Sharingdebug.entitlements new file mode 100644 index 0000000..847b16e --- /dev/null +++ b/frontend/src-tauri/gen/apple/Sharing/Sharingdebug.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.com.haystack.app + + + diff --git a/frontend/src-tauri/gen/apple/Sharing/Sharingrelease.entitlements b/frontend/src-tauri/gen/apple/Sharing/Sharingrelease.entitlements new file mode 100644 index 0000000..847b16e --- /dev/null +++ b/frontend/src-tauri/gen/apple/Sharing/Sharingrelease.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.com.haystack.app + + + diff --git a/frontend/src-tauri/tauri.conf.json b/frontend/src-tauri/tauri.conf.json index 711ee51..7863ea8 100644 --- a/frontend/src-tauri/tauri.conf.json +++ b/frontend/src-tauri/tauri.conf.json @@ -25,6 +25,9 @@ "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico" - ] + ], + "macOS": { + "signingIdentity": "6F3F957C06DE870B9A9F2CA8C2E762C6752AB2CB" + } } }