Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(ios): fallback for failed native photo picker (#4040)
Peter Chinman823e9030288c
diff --git a/js/app/packages/channel/Input/InputActions.tsx b/js/app/packages/channel/Input/InputActions.tsxindex 28e50b0f43..c1ebc79636 100644--- a/js/app/packages/channel/Input/InputActions.tsx+++ b/js/app/packages/channel/Input/InputActions.tsx@@ -45,21 +45,49 @@ export function AttachFilesAction() {export function AttachNativeMediaAction() {const commands = useInputCommands();+ let fileInputRef: HTMLInputElement | undefined;++ const onAttachFiles: JSX.EventHandlerUnion<HTMLInputElement, Event> = (+ event+ ) => {+ const files = Array.from(event.currentTarget.files ?? []);+ event.currentTarget.value = '';+ if (files.length === 0) return;+ void commands.attachFiles(files);+ };const onAttachMedia = async () => {const files = await pickNativePhotoLibraryMedia();+ if (files === null) {+ fileInputRef?.click();+ return;+ }if (files.length > 0) {await commands.attachFiles(files);}};return (- <InputActionButton- label="Attach photos or videos"- onClick={() => void onAttachMedia()}- >- <PaperclipIcon />- </InputActionButton>+ <>+ {/* File Input backup in case native photo picker fails */}+ <input+ ref={(element) => {+ fileInputRef = element;+ }}+ type="file"+ class="hidden"+ multiple+ accept={CHANNEL_FILE_PICKER_ACCEPT}+ onChange={onAttachFiles}+ data-input-attach-media-picker+ />+ <InputActionButton+ label="Attach photos or videos"+ onClick={() => void onAttachMedia()}+ >+ <PaperclipIcon />+ </InputActionButton>+ </>);}diff --git a/js/app/packages/channel/Input/create-collapsed-input-state.ts b/js/app/packages/channel/Input/create-collapsed-input-state.tsindex 898ee50b1a..4e2f3c318d 100644--- a/js/app/packages/channel/Input/create-collapsed-input-state.ts+++ b/js/app/packages/channel/Input/create-collapsed-input-state.ts@@ -27,7 +27,13 @@ export function createCollapsedInputState(options: {const attach = () => {if (isPlatform('ios')) {- void pickNativePhotoLibraryMedia().then(attachFiles);+ void pickNativePhotoLibraryMedia().then((files) => {+ if (files === null) {+ filePickerRef?.click();+ return;+ }+ return attachFiles(files);+ });return;}filePickerRef?.click();diff --git a/js/app/packages/core/mobile/nativePhotoLibrary.ts b/js/app/packages/core/mobile/nativePhotoLibrary.tsindex ff5e489ace..677f2df73b 100644--- a/js/app/packages/core/mobile/nativePhotoLibrary.ts+++ b/js/app/packages/core/mobile/nativePhotoLibrary.ts@@ -4,8 +4,14 @@ import {type NativeStagedUploadData,} from './nativeStagedUpload';-export async function pickNativePhotoLibraryMedia(): Promise<File[]> {- if (!isTauri()) return [];+/**+ * Opens the native iOS photo library picker.+ *+ * Returns the picked files (empty when the user cancels), or `null` when the+ * native picker is unavailable so callers can fall back to a file input.+ */+export async function pickNativePhotoLibraryMedia(): Promise<File[] | null> {+ if (!isTauri()) return null;let media: NativeStagedUploadData[];try {@@ -14,7 +20,7 @@ export async function pickNativePhotoLibraryMedia(): Promise<File[]> {);} catch (error) {console.warn('Photo library picker failed', error);- return [];+ return null;}return mediadiff --git a/js/app/tauri/photo_library_plugin/ios/Sources/PhotoLibraryPlugin.swift b/js/app/tauri/photo_library_plugin/ios/Sources/PhotoLibraryPlugin.swiftindex b2a3ed7efb..04024b2597 100644--- a/js/app/tauri/photo_library_plugin/ios/Sources/PhotoLibraryPlugin.swift+++ b/js/app/tauri/photo_library_plugin/ios/Sources/PhotoLibraryPlugin.swift@@ -42,7 +42,13 @@ class PhotoLibraryPlugin: Plugin {// open again instead of being stuck "already open".self.pickerDelegate = nil- guard let rootViewController = self.manager.viewController else {+ // `manager.viewController` is a singleton set through an FFI+ // callback and has been observed nil in archive builds; fall back+ // to the key window so the picker can still present.+ guard+ let rootViewController = self.manager.viewController+ ?? keyWindowRootViewController()+ else {invoke.reject("No view controller available to present photo library")return}@@ -290,6 +296,15 @@ private class PhotoLibraryPickerDelegate: NSObject, PHPickerViewControllerDelega}}+@available(iOS 14.0, *)+private func keyWindowRootViewController() -> UIViewController? {+ let windows = UIApplication.shared.connectedScenes+ .compactMap { $0 as? UIWindowScene }+ .filter { $0.activationState == .foregroundActive }+ .flatMap(\.windows)+ return (windows.first { $0.isKeyWindow } ?? windows.first)?.rootViewController+}+@available(iOS 14.0, *)private func topmostPresentableViewController(from root: UIViewController) -> UIViewController? {var current = root