From db9b9a64b4927fa1a2cdf2b7d8fda22aaf793bf3 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Feb 2024 14:05:18 +0800 Subject: [PATCH] Add method to get fast enumeration state (if possible) in FileProviderXPC Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc.h | 3 +++ src/gui/macOS/fileproviderxpc_mac.mm | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 9e234ae2e..af4a5fd7b 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -34,6 +34,9 @@ class FileProviderXPC : public QObject public: explicit FileProviderXPC(QObject *parent = nullptr); + // Returns enabled and set state of fast enumeration for the given extension + [[nodiscard]] std::optional> fastEnumerationStateForExtension(const QString &extensionAccountId) const; + public slots: void connectToExtensions(); void configureExtensions(); diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index 260804b71..5fb39debe 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -137,4 +137,25 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc } } +std::optional> FileProviderXPC::fastEnumerationStateForExtension(const QString &extensionAccountId) const +{ + qCInfo(lcFileProviderXPC) << "Checking if fast enumeration is enabled for extension" << extensionAccountId; + const auto service = (NSObject *)_clientCommServices.value(extensionAccountId); + if (service == nil) { + qCWarning(lcFileProviderXPC) << "Could not get service for extension" << extensionAccountId; + return std::nullopt; + } + + __block BOOL receivedFastEnumerationEnabled; // What is the value of the setting being used by the extension? + __block BOOL receivedFastEnumerationSet; // Has the setting been set by the user? + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + [service getFastEnumerationStateWithCompletionHandler:^(BOOL enabled, BOOL set) { + receivedFastEnumerationEnabled = enabled; + receivedFastEnumerationSet = set; + dispatch_semaphore_signal(semaphore); + }]; + dispatch_wait(semaphore, DISPATCH_TIME_FOREVER); + return std::optional>{{receivedFastEnumerationEnabled, receivedFastEnumerationSet}}; +} + } // namespace OCC::Mac -- 2.30.2