From ea0ae333d946d7316920b37e0e146faa4011c048 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 19 Jul 2024 14:51:37 +0800 Subject: [PATCH] Add method to fileproviderxpc to check if the file provider extension is reachable Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc.h | 2 ++ src/gui/macOS/fileproviderxpc_mac.mm | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 58c6a0211..4ca88c03b 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -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> fastEnumerationStateForExtension(const QString &extensionAccountId) const; diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index cc0b7b467..e94dc2cbc 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -141,6 +141,22 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc } } +bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const +{ + const auto service = (NSObject *)_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> FileProviderXPC::fastEnumerationStateForExtension(const QString &extensionAccountId) const { qCInfo(lcFileProviderXPC) << "Checking if fast enumeration is enabled for extension" << extensionAccountId;