From 8372cd7ff978052cd667953ef0dd0f70e7fead4c Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:05:05 -0800 Subject: [PATCH 1/3] fix: isolate Quick Look photo edit sessions Keep hasChangesQuickLook per NCViewerQuickLook instance, so opening another editor no longer resets the save prompt of an earlier one. Copy the photo to edit to a stable per-photo path, tmp/QuickLookEdit//, so photos with the same name never share a temporary file and repeated edits replace the copy instead of leaving new ones behind. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- .../Networking/NCNetworking+TransferDelegate.swift | 5 ++++- .../Viewer/NCViewerQuickLook/NCViewerQuickLook.swift | 12 +++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/iOSClient/Networking/NCNetworking+TransferDelegate.swift b/iOSClient/Networking/NCNetworking+TransferDelegate.swift index f3f952468c..5f3df30788 100644 --- a/iOSClient/Networking/NCNetworking+TransferDelegate.swift +++ b/iOSClient/Networking/NCNetworking+TransferDelegate.swift @@ -64,7 +64,10 @@ extension NCNetworking: NCTransferDelegate { fileName: metadata.fileNameView, userId: metadata.userId, urlBase: metadata.urlBase) - let fileNameTemp = NSTemporaryDirectory() + metadata.fileNameView + // One stable copy per photo, so repeated edits overwrite it instead of piling up. + let directoryTemp = NSTemporaryDirectory() + "QuickLookEdit/" + metadata.ocId + try? FileManager.default.createDirectory(atPath: directoryTemp, withIntermediateDirectories: true) + let fileNameTemp = directoryTemp + "/" + metadata.fileNameView let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNameTemp), isEditingEnabled: true, metadata: metadata) if let image = UIImage(contentsOfFile: fileNamePath) { if let data = image.jpegData(compressionQuality: 1) { diff --git a/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift b/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift index 43d843e6ed..3af2cb754f 100644 --- a/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift +++ b/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift @@ -19,10 +19,9 @@ public extension NCViewerQuickLookDelegate { func dismissQuickLook(fileNameSource: String, hasChangesQuickLook: Bool) {} } -/// Flag indicating If the document has any changes -private var hasChangesQuickLook: Bool = false - @objc class NCViewerQuickLook: QLPreviewController { + /// Flag indicating If the document has any changes + private var hasChangesQuickLook: Bool = false private let url: URL private let fileNameSource: String private var previewItems: [PreviewItem] = [] @@ -61,7 +60,6 @@ private var hasChangesQuickLook: Bool = false self.dataSource = self self.delegate = self self.currentPreviewItemIndex = 0 - hasChangesQuickLook = false } override func viewDidLoad() { @@ -133,7 +131,7 @@ private var hasChangesQuickLook: Bool = false } else { alertController.addAction(UIAlertAction(title: NSLocalizedString("_overwrite_original_", comment: ""), style: .default) { _ in self.saveModifiedFile(override: true) - self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: hasChangesQuickLook) + self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: self.hasChangesQuickLook) }) } @@ -142,7 +140,7 @@ private var hasChangesQuickLook: Bool = false if saveAsCopyAlert { alertController.addAction(UIAlertAction(title: NSLocalizedString("_save_as_copy_", comment: ""), style: .default) { _ in self.saveModifiedFile(override: false) - self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: hasChangesQuickLook) + self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: self.hasChangesQuickLook) }) } alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in @@ -156,7 +154,7 @@ private var hasChangesQuickLook: Bool = false @objc private func dismissView(_ sender: Any?) { dismiss(animated: true) { - if hasChangesQuickLook { + if self.hasChangesQuickLook { self.showSaveAlert() } } From 705a13dee4a6c4323ad178a9320f2daffdcca0ee Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:05:05 -0800 Subject: [PATCH 2/3] fix: offer Edit for photos whose original is not downloaded yet The viewer menu showed Modify only when the original was already on the device. Show Edit for images Quick Look can modify when the device is online or the file is stored locally, and use the Edit title in the file context menu too. When the original is missing, the action awaits the media viewer model's existing downloadOriginalImage(for:), which joins a download already in progress for that photo, and opens the editor only if the viewer is still on screen and showing the same photo. Local files keep the existing path. Fixes #4332 Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- iOSClient/Menu/NCContextMenuMain.swift | 2 +- iOSClient/Menu/NCContextMenuViewer.swift | 11 +++++++++-- .../NCMediaViewerHostingController.swift | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/iOSClient/Menu/NCContextMenuMain.swift b/iOSClient/Menu/NCContextMenuMain.swift index 0caf019830..26cccd1114 100644 --- a/iOSClient/Menu/NCContextMenuMain.swift +++ b/iOSClient/Menu/NCContextMenuMain.swift @@ -270,7 +270,7 @@ class NCContextMenuMain: NSObject { private func makeModifyWithQuickLookAction(metadata: tableMetadata) -> UIAction { return UIAction( - title: NSLocalizedString("_modify_", comment: ""), + title: NSLocalizedString("_edit_", comment: ""), image: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconImageColor]) ) { _ in Task { diff --git a/iOSClient/Menu/NCContextMenuViewer.swift b/iOSClient/Menu/NCContextMenuViewer.swift index a22f5f7cf4..082f425ff4 100644 --- a/iOSClient/Menu/NCContextMenuViewer.swift +++ b/iOSClient/Menu/NCContextMenuViewer.swift @@ -108,7 +108,7 @@ class NCContextMenuViewer: NSObject { if !webView, metadata.isImage, metadata.isModifiableWithQuickLook, - utilityFileSystem.fileSizeIfExists(metadata) { + NCNetworking.shared.isOnline || utilityFileSystem.fileSizeIfExists(metadata) { editingActions.append(makeModifyPhoto()) } @@ -296,10 +296,17 @@ class NCContextMenuViewer: NSObject { private func makeModifyPhoto() -> UIAction { return UIAction( - title: NSLocalizedString("_modify_", comment: ""), + title: NSLocalizedString("_edit_", comment: ""), image: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconImageColor]) ) { _ in Task { + if !self.utilityFileSystem.fileSizeIfExists(self.metadata) { + // Only a preview is on the device: let the media viewer download the original first. + guard let viewer = self.viewController as? NCMediaViewerHostingController, + await viewer.downloadOriginalForEditing(self.metadata) else { + return + } + } await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in delegate.transferChange( networkingStatus: NCGlobal.shared.networkingStatusDownloaded, diff --git a/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift b/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift index 24febdc3ce..7febfedd89 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift @@ -525,6 +525,17 @@ final class NCMediaViewerHostingController: UIHostingController Bool { + do { + try await model.downloadOriginalImage(for: model.viewerItem(from: metadata)) + } catch { + return false + } + return viewIfLoaded?.window != nil && model.selectedMetadata?.ocId == metadata.ocId + } } // MARK: - Media Viewer Transfer Delegate From f46eae157f625052428c8f3d06d601b77c029a68 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Fri, 27 Nov 2026 05:43:06 -0800 Subject: [PATCH 3/3] fix: show progress and errors when Edit downloads the original Opening Edit from a photo preview can take time or fail before the editor appears. Show that the original is downloading and explain failures while the requested photo is still selected. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- .../NCViewerMedia/Core/NCMediaViewerModel.swift | 12 +++++++++++- .../NCMediaViewerHostingController.swift | 15 ++++++++++++++- .../Views/NCMediaViewerPageView.swift | 13 +++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/iOSClient/Viewer/NCViewerMedia/Core/NCMediaViewerModel.swift b/iOSClient/Viewer/NCViewerMedia/Core/NCMediaViewerModel.swift index e7dac38af0..f4daa8e53a 100644 --- a/iOSClient/Viewer/NCViewerMedia/Core/NCMediaViewerModel.swift +++ b/iOSClient/Viewer/NCViewerMedia/Core/NCMediaViewerModel.swift @@ -149,7 +149,7 @@ final class NCMediaViewerModel: ObservableObject { private var viewerDownloadedLivePhotoOcIds = Set() // Also serialize a quick close/reopen against the previous viewer's pending removals. private static var releasingImagesByAccount: [String: [String: Task]] = [:] - private var isClosed = false + private(set) var isClosed = false private var previewSelectionID: UUID? private var thumbnailScrubID: UUID? @@ -740,6 +740,16 @@ final class NCMediaViewerModel: ObservableObject { } guard thumbnailScrubID == nil else { return } + let isImage = metadata.classFile == NKTypeClassFile.image.rawValue + if isImage { + setState(.downloading(previewURL: previewURL, progress: nil), for: ocId) + } + defer { + if isImage, case .downloading = pageState(for: ocId) { + setState(.image(previewURL: previewURL, localURL: nil, livePhotoURL: nil, progress: nil), for: ocId) + } + } + do { let downloadedURL = try await loader.downloadMedia(for: metadata, onDownloadStarted: nil) viewerDownloadedOcIds.insert(ocId) diff --git a/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift b/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift index 7febfedd89..942e5143a4 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCMediaViewerHostingController.swift @@ -529,12 +529,25 @@ final class NCMediaViewerHostingController: UIHostingController Bool { + let ocId = metadata.ocId + var isStillViewingPhoto: Bool { + !model.isClosed && viewIfLoaded?.window != nil && model.selectedMetadata?.ocId == ocId + } + guard isStillViewingPhoto else { return false } + do { + // This delegates to loadPageIfNeeded instead of downloading directly. + // NCMediaViewerLoadingPolicy.shouldDownloadOriginalImage controls the fetch + // (enabled by automaticallyDownloadsOriginalImages: true in NCMediaViewerModel+App.swift). + // If the policy skips the original, CancellationError is reported below. try await model.downloadOriginalImage(for: model.viewerItem(from: metadata)) } catch { + if isStillViewingPhoto { + await showErrorBanner(windowScene: viewIfLoaded?.window?.windowScene, text: "_status_download_error_") + } return false } - return viewIfLoaded?.window != nil && model.selectedMetadata?.ocId == metadata.ocId + return isStillViewingPhoto } } diff --git a/iOSClient/Viewer/NCViewerMedia/Views/NCMediaViewerPageView.swift b/iOSClient/Viewer/NCViewerMedia/Views/NCMediaViewerPageView.swift index ebce94e652..fdbecccf1d 100644 --- a/iOSClient/Viewer/NCViewerMedia/Views/NCMediaViewerPageView.swift +++ b/iOSClient/Viewer/NCViewerMedia/Views/NCMediaViewerPageView.swift @@ -227,6 +227,19 @@ struct NCMediaViewerPageView: View { @ViewBuilder private func downloadingStateView(previewURL: URL?, _ progress: Double?) -> some View { switch page.metadata?.classFile { + case NKTypeClassFile.image.rawValue: + imageStateView(previewURL: previewURL, localURL: nil, livePhotoURL: nil) + .overlay { + if isSelected { + ProgressView() + .tint(.white) + .padding(12) + .background(.black.opacity(0.65), in: Circle()) + .accessibilityLabel(Text(NSLocalizedString("_download_in_progress_", comment: ""))) + .allowsHitTesting(false) + } + } + case NKTypeClassFile.video.rawValue: if isSelected { videoStateView(localURL: nil, previewURL: previewURL)