Extract display updating upon url acquisition to different method in ShareViewController
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 21 Feb 2024 10:59:39 +0000 (18:59 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 08:38:45 +0000 (16:38 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift

index 068349e269a3e8c246a2af7dcd231b5dd7878036..756eb9210241509908f8e30d96c65575e84a304f 100644 (file)
@@ -49,32 +49,14 @@ class ShareViewController: NSViewController {
         actionViewController.extensionContext.completeRequest()
     }
 
-    func processItemIdentifier(_ itemIdentifier: NSFileProviderItemIdentifier) async {
+    private func processItemIdentifier(_ itemIdentifier: NSFileProviderItemIdentifier) async {
         guard let manager = NSFileProviderManager(for: actionViewController.domain) else {
             fatalError("NSFileProviderManager isn't expected to fail")
         }
 
         do {
             let itemUrl = try await manager.getUserVisibleURL(for: itemIdentifier)
-            fileNameLabel.stringValue = itemUrl.lastPathComponent
-
-            let request = QLThumbnailGenerator.Request(
-                fileAt: itemUrl,
-                size: CGSize(width: 128, height: 128),
-                scale: 1.0,
-                representationTypes: .icon
-            )
-
-            let generator = QLThumbnailGenerator.shared
-            let fileThumbnail = await withCheckedContinuation { continuation in
-                generator.generateRepresentations(for: request) { thumbnail, type, error in
-                    if thumbnail == nil || error != nil {
-                        Logger.shareViewController.error("Could not get thumbnail: \(error)")
-                    }
-                    continuation.resume(returning: thumbnail)
-                }
-            }
-            fileNameIcon.image = fileThumbnail?.nsImage
+            await updateDisplay(itemUrl: itemUrl)
         } catch let error {
             let errorString = "Error processing item: \(error)"
             Logger.shareViewController.error("\(errorString)")
@@ -82,4 +64,26 @@ class ShareViewController: NSViewController {
             descriptionLabel.stringValue = errorString
         }
     }
+
+    private func updateDisplay(itemUrl: URL) async {
+        fileNameLabel.stringValue = itemUrl.lastPathComponent
+
+        let request = QLThumbnailGenerator.Request(
+            fileAt: itemUrl,
+            size: CGSize(width: 128, height: 128),
+            scale: 1.0,
+            representationTypes: .icon
+        )
+
+        let generator = QLThumbnailGenerator.shared
+        let fileThumbnail = await withCheckedContinuation { continuation in
+            generator.generateRepresentations(for: request) { thumbnail, type, error in
+                if thumbnail == nil || error != nil {
+                    Logger.shareViewController.error("Could not get thumbnail: \(error)")
+                }
+                continuation.resume(returning: thumbnail)
+            }
+        }
+        fileNameIcon.image = fileThumbnail?.nsImage
+    }
 }