Use new convenience method to get Item for root container from NCFPK

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-04-15 19:40:53 +08:00
parent d74d23cedb
commit 6200cab957
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -85,10 +85,11 @@ import OSLog
) )
} }
// MARK: NSFileProviderReplicatedExtension protocol methods // MARK: - NSFileProviderReplicatedExtension protocol methods
func item( func item(
for identifier: NSFileProviderItemIdentifier, request _: NSFileProviderRequest, for identifier: NSFileProviderItemIdentifier,
request _: NSFileProviderRequest,
completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void
) -> Progress { ) -> Progress {
// resolve the given identifier to a record in the model // resolve the given identifier to a record in the model
@ -96,8 +97,9 @@ import OSLog
Logger.fileProviderExtension.debug( Logger.fileProviderExtension.debug(
"Received item request for item with identifier: \(identifier.rawValue, privacy: .public)" "Received item request for item with identifier: \(identifier.rawValue, privacy: .public)"
) )
if identifier == .rootContainer { if identifier == .rootContainer {
guard let ncAccount else { guard ncAccount != nil else {
Logger.fileProviderExtension.error( Logger.fileProviderExtension.error(
"Not providing item: \(identifier.rawValue, privacy: .public) as account not set up yet" "Not providing item: \(identifier.rawValue, privacy: .public) as account not set up yet"
) )
@ -105,20 +107,7 @@ import OSLog
return Progress() return Progress()
} }
let metadata = ItemMetadata() completionHandler(Item.rootContainer(ncKit: ncKit), nil)
metadata.account = ncAccount.ncKitAccount
metadata.directory = true
metadata.ocId = NSFileProviderItemIdentifier.rootContainer.rawValue
metadata.fileName = "root"
metadata.fileNameView = "root"
metadata.serverUrl = ncAccount.serverUrl
metadata.classFile = NKCommon.TypeClassFile.directory.rawValue
completionHandler(
Item(metadata: metadata, parentItemIdentifier: .rootContainer, ncKit: ncKit),
nil
)
return Progress() return Progress()
} }
@ -132,8 +121,7 @@ import OSLog
} }
completionHandler( completionHandler(
Item(metadata: metadata, parentItemIdentifier: parentItemIdentifier, ncKit: ncKit), Item(metadata: metadata, parentItemIdentifier: parentItemIdentifier, ncKit: ncKit), nil
nil
) )
return Progress() return Progress()
} }