diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index e4833e8ae1..09164772a6 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -125,6 +125,8 @@ void FileProviderXPC::start() return; } + NSMutableArray *const connections = NSMutableArray.array; + for (NSDictionary *const services in fpServices) { NSArray *const serviceNamesArray = services.allKeys; @@ -153,25 +155,38 @@ void FileProviderXPC::start() return; } - connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(ClientCommunicationProtocol)]; - [connection resume]; - const id clientCommService = (id)[connection remoteObjectProxyWithErrorHandler:^(NSError *const error){ - qCWarning(lcFileProviderXPC) << "Error getting remote object proxy" << error; - dispatch_group_leave(group); - }]; - - if (clientCommService == nil) { - qCWarning(lcFileProviderXPC) << "Client communication service is nil"; - dispatch_group_leave(group); - return; - } - + [connection retain]; + [connections addObject:connection]; dispatch_group_leave(group); }]; } } dispatch_group_wait(group, DISPATCH_TIME_FOREVER); + + for (NSXPCConnection * const connection in connections) { + Q_ASSERT(connection != nil); + connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(ClientCommunicationProtocol)]; + connection.interruptionHandler = ^{ + qCInfo(lcFileProviderXPC) << "File provider connection interrupted"; + }; + connection.invalidationHandler = ^{ + qCInfo(lcFileProviderXPC) << "File provider connection invalidated"; + }; + [connection resume]; + + const id remoteServiceObject = [connection remoteObjectProxyWithErrorHandler:^(NSError *const error){ + qCWarning(lcFileProviderXPC) << "Error getting remote object proxy" << error; + }]; + + NSObject *const clientCommService = (NSObject *)remoteServiceObject; + if (clientCommService == nil) { + qCWarning(lcFileProviderXPC) << "Client communication service is nil"; + continue; + } + + [clientCommService retain]; + } } } // namespace OCC