Submit tasks to do after readding file provider domain as completion blocks

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-13 16:47:18 +01:00
parent 002a75bca1
commit 89d48ec8cc
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -290,7 +290,7 @@ class FileProviderDomainManager::Private {
Q_ASSERT(account);
const auto domainId = domainIdentifierForAccount(account);
qCDebug(lcMacFileProviderDomainManager) << "Removing file provider domain with id: " << domainId;
qCDebug(lcMacFileProviderDomainManager) << "Disconnecting file provider domain with id: " << domainId;
if(!_registeredDomains.contains(domainId)) {
qCDebug(lcMacFileProviderDomainManager) << "File provider domain not found for id: " << domainId;
@ -301,11 +301,7 @@ class FileProviderDomainManager::Private {
Q_ASSERT(fileProviderDomain != nil);
NSFileProviderManager * const fpManager = [NSFileProviderManager managerForDomain:fileProviderDomain];
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain);
return;
}
void (^disconnectBlock)(void) = ^{
[fpManager disconnectWithReason:message.toNSString()
options:NSFileProviderManagerDisconnectionOptionsTemporary
completionHandler:^(NSError * const error) {
@ -320,6 +316,14 @@ class FileProviderDomainManager::Private {
qCDebug(lcMacFileProviderDomainManager) << "Successfully disconnected file provider domain: "
<< fileProviderDomain.displayName;
}];
};
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain, disconnectBlock);
return;
}
disconnectBlock();
}
void reconnectFileProviderDomainForAccount(const AccountState * const accountState)
@ -329,7 +333,7 @@ class FileProviderDomainManager::Private {
Q_ASSERT(account);
const auto domainId = domainIdentifierForAccount(account);
qCDebug(lcMacFileProviderDomainManager) << "Removing file provider domain with id: " << domainId;
qCDebug(lcMacFileProviderDomainManager) << "Reconnecting file provider domain with id: " << domainId;
if(!_registeredDomains.contains(domainId)) {
qCDebug(lcMacFileProviderDomainManager) << "File provider domain not found for id: " << domainId;
@ -340,11 +344,7 @@ class FileProviderDomainManager::Private {
Q_ASSERT(fileProviderDomain != nil);
NSFileProviderManager * const fpManager = [NSFileProviderManager managerForDomain:fileProviderDomain];
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain);
return;
}
void (^reconnectBlock)(void) = ^{
[fpManager reconnectWithCompletionHandler:^(NSError * const error) {
if (error) {
qCDebug(lcMacFileProviderDomainManager) << "Error reconnecting file provider domain: "
@ -357,6 +357,14 @@ class FileProviderDomainManager::Private {
qCDebug(lcMacFileProviderDomainManager) << "Successfully reconnected file provider domain: "
<< fileProviderDomain.displayName;
}];
};
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain, reconnectBlock);
return;
}
reconnectBlock();
}
void signalEnumeratorChanged(const Account * const account)
@ -375,17 +383,21 @@ class FileProviderDomainManager::Private {
Q_ASSERT(fileProviderDomain != nil);
NSFileProviderManager * const fpManager = [NSFileProviderManager managerForDomain:fileProviderDomain];
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain);
return;
}
void (^signalEnumeratorBlock)(void) = ^{
[fpManager signalEnumeratorForContainerItemIdentifier:NSFileProviderWorkingSetContainerItemIdentifier completionHandler:^(NSError * const error) {
if (error != nil) {
qCDebug(lcMacFileProviderDomainManager) << "Error signalling enumerator changed for working set:"
<< error.localizedDescription;
}
}];
};
if (fpManager == nil) {
readdFileProviderDomain(fileProviderDomain, signalEnumeratorBlock);
return;
}
signalEnumeratorBlock();
}
private: