From 1288448336a41c46b4fa4a972f12887d6a586566 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 27 Feb 2024 20:28:55 +0800 Subject: [PATCH] Add item shares loading routine to ShareTableViewDataSource Signed-off-by: Claudio Cambra --- .../Extensions/Logger+Extensions.swift | 1 + .../ShareTableViewDataSource.swift | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift index 8ec218668..63ff845a6 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift @@ -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") } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift index 77fc2e42f..7d19fb7fe 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift @@ -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 {