From 95bebc52140a74e3092683266705213ce7074aaf Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 27 Dec 2023 19:10:37 +0800 Subject: [PATCH] Clean up FileProviderXPC code, separate everything into single-responsibility methods Signed-off-by: Claudio Cambra --- src/gui/macOS/fileprovider_mac.mm | 3 ++- src/gui/macOS/fileproviderxpc.h | 11 ++++++++++- src/gui/macOS/fileproviderxpc_mac.mm | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/gui/macOS/fileprovider_mac.mm b/src/gui/macOS/fileprovider_mac.mm index 00cd3aa12..c6a7f572e 100644 --- a/src/gui/macOS/fileprovider_mac.mm +++ b/src/gui/macOS/fileprovider_mac.mm @@ -60,7 +60,8 @@ FileProvider::FileProvider(QObject * const parent) _xpc = std::make_unique(new FileProviderXPC(this)); if (_xpc) { qCInfo(lcMacFileProvider) << "Initialised file provider XPC."; - _xpc->start(); + _xpc->connectToExtensions(); + _xpc->configureExtensions(); } else { qCWarning(lcMacFileProvider) << "Could not initialise file provider XPC."; } diff --git a/src/gui/macOS/fileproviderxpc.h b/src/gui/macOS/fileproviderxpc.h index 759a4a059..a145b7104 100644 --- a/src/gui/macOS/fileproviderxpc.h +++ b/src/gui/macOS/fileproviderxpc.h @@ -16,6 +16,8 @@ #include +#import + namespace OCC { namespace Mac { @@ -28,7 +30,14 @@ public: explicit FileProviderXPC(QObject *parent = nullptr); public slots: - void start(); + void connectToExtensions(); + void configureExtensions(); + +private: + void setupConnections(); + void processConnections(NSArray *const services); + + NSArray *_clientCommServices; }; } diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index b8cb5e049..5d9ca2750 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -32,7 +32,7 @@ FileProviderXPC::FileProviderXPC(QObject *parent) { } -void FileProviderXPC::start() +void FileProviderXPC::connectToExtensions() { qCInfo(lcFileProviderXPC) << "Starting file provider XPC"; @@ -40,6 +40,11 @@ void FileProviderXPC::start() const auto domainUrls = FileProviderXPCUtils::getDomainUrlsForManagers(managers); const auto fpServices = FileProviderXPCUtils::getFileProviderServicesAtUrls(domainUrls); const auto connections = FileProviderXPCUtils::connectToFileProviderServices(fpServices); + processConnections(connections); +} + +void FileProviderXPC::processConnections(NSArray *const connections) +{ dispatch_group_t group = dispatch_group_create(); NSMutableDictionary*> *const clientCommServices = NSMutableDictionary.dictionary; @@ -95,7 +100,12 @@ void FileProviderXPC::start() [clientCommServices setObject:clientCommService forKey:extensionNcAccount]; } - for (NSString *const extensionNcAccount in clientCommServices) { + _clientCommServices = clientCommServices.copy; +} + +void FileProviderXPC::configureExtensions() +{ + for (NSString *const extensionNcAccount in _clientCommServices) { qCInfo(lcFileProviderXPC) << "Sending message to client communication service"; const auto qExtensionNcAccount = QString::fromNSString(extensionNcAccount); @@ -116,7 +126,7 @@ void FileProviderXPC::start() NSString *const serverUrl = account->url().toString().toNSString(); NSString *const password = credentials->password().toNSString(); - NSObject *const clientCommService = [clientCommServices objectForKey:extensionNcAccount]; + NSObject *const clientCommService = [_clientCommServices objectForKey:extensionNcAccount]; [clientCommService configureAccountWithUser:user serverUrl:serverUrl password:password];