Add item shares loading routine to ShareTableViewDataSource

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-02-27 20:28:55 +08:00
parent 6dad778498
commit 1288448336
2 changed files with 21 additions and 0 deletions

View 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")
}

View 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 {