Add method to set fast enumeration in client communication service
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 5 Feb 2024 10:50:29 +0000 (18:50 +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>
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/ClientCommunicationProtocol.h
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/ClientCommunicationService.swift

index 481f541c5bcf45ab1f4b0ae61822332a54b4dd6b..1ab5e8853d284301a519e239a8266a8736996138 100644 (file)
@@ -26,6 +26,7 @@
 - (void)removeAccountConfig;
 - (void)createDebugLogStringWithCompletionHandler:(void(^)(NSString *debugLogString, NSError *error))completionHandler;
 - (void)getFastEnumerationStateWithCompletionHandler:(void(^)(BOOL enabled, BOOL set))completionHandler;
+- (void)setFastEnumerationEnabled:(BOOL)enabled;
 
 @end
 
index 3b93641411a54bae1b59f4d6ad419fab62564276..648b686a1636ee7b8c578f1996ffcb281d5e9959 100644 (file)
@@ -83,4 +83,22 @@ class ClientCommunicationService: NSObject, NSFileProviderServiceSource, NSXPCLi
         let set = fpExtension.config.fastEnumerationSet
         completionHandler(enabled, set)
     }
+
+    func setFastEnumerationEnabled(_ enabled: Bool) {
+        fpExtension.config.fastEnumerationEnabled = enabled
+
+        guard enabled else { return }
+        // If enabled, start full enumeration
+        guard let fpManager = NSFileProviderManager(for: fpExtension.domain) else {
+            let domainName = self.fpExtension.domain.displayName
+            Logger.fileProviderExtension.error("Could not get file provider manager for domain \(domainName, privacy: .public), cannot run enumeration after fast enumeration setting change")
+            return
+        }
+
+        fpManager.signalEnumerator(for: .workingSet) { error in
+            if error != nil {
+                Logger.fileProviderExtension.error("Error signalling enumerator for working set, received error: \(error!.localizedDescription, privacy: .public)")
+            }
+        }
+    }
 }