Add item shares loading routine to ShareTableViewDataSource
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 27 Feb 2024 12:28:55 +0000 (20:28 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 08:38:47 +0000 (16:38 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift

index 8ec218668472fef1ba6bc1975ec87cdc6d00535d..63ff845a69d8026143046f8b65a485719f18d7d8 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 sharesDataSource = Logger(subsystem: subsystem, category: "sharesDataSource")
     static let shareViewController = Logger(subsystem: subsystem, category: "shareViewController")
 }
 
index 77fc2e42f2ca18194077b814af82be071beea426..7d19fb7fe91e2e9b7b6db246bc72a8d6aa524aad 100644 (file)
@@ -8,6 +8,8 @@
 import AppKit
 import FileProvider
 import NextcloudKit
+import OSLog
+
 class ShareTableViewDataSource: NSObject, NSTableViewDataSource {
     var sharesTableView: NSTableView? {
         didSet {
@@ -21,6 +23,24 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource {
         didSet { sharesTableView?.reloadData() }
     }
 
+    func loadItem(identifier: NSFileProviderItemIdentifier, url: URL) {
+        itemIdentifier = identifier
+        itemURL = url
+        Task {
+            await reload()
+        }
+    }
+
+    private func reload() async {
+        guard let itemIdentifier = itemIdentifier, let itemURL = itemURL else { return }
+        do {
+            let connection = try await serviceConnection(url: itemURL)
+            shares = await connection.shares(forItemIdentifier: itemIdentifier) ?? []
+        } catch let error {
+            Logger.sharesDataSource.error("Could not reload data: \(error)")
+        }
+    }
+
     private func serviceConnection(url: URL) async throws -> FPUIExtensionService {
         let services = try await FileManager().fileProviderServicesForItem(at: url)
         guard let service = services[fpUiExtensionServiceName] else {