Better handle initial set up of the file provider extension

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-09 19:00:35 +01:00
parent 03c1731fb5
commit b73c1d72fb
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -567,7 +567,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> NSFileProviderEnumerator {
guard let ncAccount = ncAccount else {
NSLog("Not providing enumerator for container with identifier %@ yet as account not set up")
NSLog("Not providing enumerator for container with identifier %@ yet as account not set up", containerItemIdentifier.rawValue)
itemIdsForEnumeratorsNeedingSignalling.add(containerItemIdentifier)
throw NSFileProviderError(.notAuthenticated)
}
@ -591,22 +591,37 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
assert(ncAccount != nil)
if !NextcloudFilesDatabaseManager.shared.anyItemMetadatasForAccount(ncAccount!.ncKitAccount) {
fpManager.signalErrorResolved(NSFileProviderError(.notAuthenticated)) { error in
if error != nil {
NSLog("Error resolving not authenticated, received error: %@", error!.localizedDescription)
}
}
guard NextcloudFilesDatabaseManager.shared.anyItemMetadatasForAccount(ncAccount!.ncKitAccount) else {
// When we have nothing registered, force full refresh.
// This refreshes the entire structure of the FileProvider and calls
// enumerateItems rather than enumerateChanges in the enumerator
NSLog("Signalling manager for user %@ at server %@ to reimport everything", ncAccount!.username, ncAccount!.serverUrl)
fpManager.reimportItems(below: .rootContainer, completionHandler: {_ in })
fpManager.reimportItems(below: .rootContainer) { error in
if error != nil {
NSLog("Error reimporting everything, received error: %@", error!.localizedDescription)
}
}
itemIdsForEnumeratorsNeedingSignalling = NSMutableSet()
return
}
NSLog("Signalling enumerator for user %@ at server %@", ncAccount!.username, ncAccount!.serverUrl)
// System will only respond to workingSet when using and NSFileProviderReplicatedExtension
// https://developer.apple.com/documentation/fileprovider/nonreplicated_file_provider_extension/content_and_change_tracking/tracking_your_file_provider_s_changes/using_push_notifications_to_signal_changes
fpManager.signalEnumerator(for: .workingSet) { error in
if error != nil {
NSLog("Error signalling enumerator for workingSet, received error: %@", error!.localizedDescription)
NSLog("Signalling enumerators for user %@ at server %@", ncAccount!.username, ncAccount!.serverUrl)
for itemId in itemIdsForEnumeratorsNeedingSignalling {
fpManager.signalEnumerator(for: itemId as! NSFileProviderItemIdentifier) { error in
if error != nil {
NSLog("Error signalling enumerator for root container, received error: %@", error!.localizedDescription)
}
}
}
itemIdsForEnumeratorsNeedingSignalling = NSMutableSet()
}
func setupDomainAccount(user: String, serverUrl: String, password: String) {
@ -621,9 +636,6 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
NSLog("Nextcloud account set up in File Provider extension for user: %@ at server: %@", user, serverUrl)
if itemIdsForEnumeratorsNeedingSignalling.count > 0 {
signalEnumeratorAfterAccountSetup()
itemIdsForEnumeratorsNeedingSignalling = NSMutableSet()
}
signalEnumeratorAfterAccountSetup()
}
}