Add method to fileproviderxpc to check if the file provider extension is reachable

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-07-19 14:51:37 +08:00
parent d3d19fd2bf
commit ea0ae333d9
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 18 additions and 0 deletions

View file

@ -34,6 +34,8 @@ class FileProviderXPC : public QObject
public:
explicit FileProviderXPC(QObject *parent = nullptr);
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId) const;
// Returns enabled and set state of fast enumeration for the given extension
[[nodiscard]] std::optional<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;

View file

@ -141,6 +141,22 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc
}
}
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const
{
const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
if (service == nil) {
return false;
}
__block auto response = false;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[service getExtensionAccountIdWithCompletionHandler:^(NSString *const, NSError *const) {
response = true;
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta));
return response;
}
std::optional<std::pair<bool, bool>> FileProviderXPC::fastEnumerationStateForExtension(const QString &extensionAccountId) const
{
qCInfo(lcFileProviderXPC) << "Checking if fast enumeration is enabled for extension" << extensionAccountId;