mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
Better handle initial set up of the file provider extension
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
03c1731fb5
commit
b73c1d72fb
1 changed files with 25 additions and 13 deletions
|
@ -567,7 +567,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
||||||
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> NSFileProviderEnumerator {
|
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> NSFileProviderEnumerator {
|
||||||
|
|
||||||
guard let ncAccount = ncAccount else {
|
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)
|
itemIdsForEnumeratorsNeedingSignalling.add(containerItemIdentifier)
|
||||||
throw NSFileProviderError(.notAuthenticated)
|
throw NSFileProviderError(.notAuthenticated)
|
||||||
}
|
}
|
||||||
|
@ -591,24 +591,39 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
||||||
|
|
||||||
assert(ncAccount != nil)
|
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
|
// This refreshes the entire structure of the FileProvider and calls
|
||||||
// enumerateItems rather than enumerateChanges in the enumerator
|
// enumerateItems rather than enumerateChanges in the enumerator
|
||||||
NSLog("Signalling manager for user %@ at server %@ to reimport everything", ncAccount!.username, ncAccount!.serverUrl)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog("Signalling enumerator for user %@ at server %@", ncAccount!.username, ncAccount!.serverUrl)
|
NSLog("Signalling enumerators for user %@ at server %@", ncAccount!.username, ncAccount!.serverUrl)
|
||||||
// System will only respond to workingSet when using and NSFileProviderReplicatedExtension
|
for itemId in itemIdsForEnumeratorsNeedingSignalling {
|
||||||
// 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: itemId as! NSFileProviderItemIdentifier) { error in
|
||||||
fpManager.signalEnumerator(for: .workingSet) { error in
|
|
||||||
if error != nil {
|
if error != nil {
|
||||||
NSLog("Error signalling enumerator for workingSet, received error: %@", error!.localizedDescription)
|
NSLog("Error signalling enumerator for root container, received error: %@", error!.localizedDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemIdsForEnumeratorsNeedingSignalling = NSMutableSet()
|
||||||
|
}
|
||||||
|
|
||||||
func setupDomainAccount(user: String, serverUrl: String, password: String) {
|
func setupDomainAccount(user: String, serverUrl: String, password: String) {
|
||||||
ncAccount = NextcloudAccount(user: user, serverUrl: serverUrl, password: password)
|
ncAccount = NextcloudAccount(user: user, serverUrl: serverUrl, password: password)
|
||||||
ncKit.setup(user: ncAccount!.username,
|
ncKit.setup(user: ncAccount!.username,
|
||||||
|
@ -621,9 +636,6 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
||||||
|
|
||||||
NSLog("Nextcloud account set up in File Provider extension for user: %@ at server: %@", user, serverUrl)
|
NSLog("Nextcloud account set up in File Provider extension for user: %@ at server: %@", user, serverUrl)
|
||||||
|
|
||||||
if itemIdsForEnumeratorsNeedingSignalling.count > 0 {
|
|
||||||
signalEnumeratorAfterAccountSetup()
|
signalEnumeratorAfterAccountSetup()
|
||||||
itemIdsForEnumeratorsNeedingSignalling = NSMutableSet()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue