Add method to get fast enumeration state (if possible) in FileProviderXPC
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 6 Feb 2024 06:05:18 +0000 (14:05 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 6 Mar 2024 10:46:41 +0000 (18:46 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderxpc.h
src/gui/macOS/fileproviderxpc_mac.mm

index 9e234ae2ee3dc3483b14107d9d0b1f2f8572dabe..af4a5fd7b950436c0def23ac7df5c2352e010217 100644 (file)
@@ -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<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;
+
 public slots:
     void connectToExtensions();
     void configureExtensions();
index 260804b71bc31bb0a41402466c6c3e866a59f74c..5fb39debe7872542200544b310bac7493adf5700 100644 (file)
@@ -137,4 +137,25 @@ void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAcc
     }
 }
 
+std::optional<std::pair<bool, bool>> FileProviderXPC::fastEnumerationStateForExtension(const QString &extensionAccountId) const
+{
+    qCInfo(lcFileProviderXPC) << "Checking if fast enumeration is enabled for extension" << extensionAccountId;
+    const auto service = (NSObject<ClientCommunicationProtocol> *)_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<std::pair<bool, bool>>{{receivedFastEnumerationEnabled, receivedFastEnumerationSet}};
+}
+
 } // namespace OCC::Mac