Add method to simply provide file details in locking view
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 30 Jul 2024 10:51:10 +0000 (18:51 +0800)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Thu, 12 Sep 2024 08:15:58 +0000 (10:15 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift

index 64836328b5ebd022b9c62d9dfc7f6f3ab808c339..d2e38c3cc09537e7e0c62d73bdbaf3e9d33808d7 100644 (file)
@@ -11,6 +11,7 @@ extension Logger {
     private static var subsystem = Bundle.main.bundleIdentifier!
 
     static let actionViewController = Logger(subsystem: subsystem, category: "actionViewController")
+    static let lockViewController = Logger(subsystem: subsystem, category: "lockViewController")
     static let metadataProvider = Logger(subsystem: subsystem, category: "metadataProvider")
     static let shareCapabilities = Logger(subsystem: subsystem, category: "shareCapabilities")
     static let shareController = Logger(subsystem: subsystem, category: "shareController")
index ae113bee7759efb96ecdf5643ffbb94b3ea56b3f..369ac0256212164d9e0d6c3ce3017f51b6459eec 100644 (file)
@@ -43,4 +43,31 @@ class LockViewController: NSViewController {
         Logger.lockViewController.error("Error: \(error, privacy: .public)")
         descriptionLabel.stringValue = "Error: \(error)"
     }
+
+    private func updateFileDetailsDisplay(itemUrl: URL) async {
+        let lockAction = locking ? "Locking" : "Unlocking"
+        fileNameLabel.stringValue = "\(lockAction) file \(itemUrl.lastPathComponent)…"
+
+        let request = QLThumbnailGenerator.Request(
+            fileAt: itemUrl,
+            size: CGSize(width: 48, height: 48),
+            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.lockViewController.error(
+                        "Could not get thumbnail: \(error, privacy: .public)"
+                    )
+                }
+                continuation.resume(returning: thumbnail)
+            }
+        }
+
+        fileNameIcon.image =
+            fileThumbnail?.nsImage ?? 
+            NSImage(systemSymbolName: "doc", accessibilityDescription: "doc")
+    }
 }