From efe35934adc8e5ee7143f1383957a896007552da Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 21 Feb 2024 20:23:57 +0800 Subject: [PATCH] Implement convenience method to acquire FPUIExtensionService in share view controller Signed-off-by: Claudio Cambra --- .../ShareViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift index 756eb9210..acf5f8442 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift @@ -86,4 +86,23 @@ class ShareViewController: NSViewController { } fileNameIcon.image = fileThumbnail?.nsImage } + + private func serviceConnection(url: URL) async throws -> FPUIExtensionService { + let services = try await FileManager().fileProviderServicesForItem(at: url) + guard let service = services[fpUiExtensionServiceName] else { + Logger.shareViewController.error("Couldn't get service, required service not present") + throw NSFileProviderError(.providerNotFound) + } + let connection: NSXPCConnection + connection = try await service.fileProviderConnection() + connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self) + connection.interruptionHandler = { + Logger.shareViewController.error("Service connection interrupted") + } + connection.resume() + guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else { + throw NSFileProviderError(.serverUnreachable) + } + return proxy + } } -- 2.30.2