diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/FileProviderCommunication.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/FileProviderCommunication.swift new file mode 100644 index 000000000..111e282dc --- /dev/null +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/FileProviderCommunication.swift @@ -0,0 +1,31 @@ +// +// FileProviderCommunication.swift +// FileProviderUIExt +// +// Created by Claudio Cambra on 30/7/24. +// + +import FileProvider + +enum FileProviderCommunicationError: Error { + case serviceNotFound + case remoteProxyObjectInvalid +} + +func serviceConnection( + url: URL, interruptionHandler: @escaping () -> Void +) async throws -> FPUIExtensionService { + let services = try await FileManager().fileProviderServicesForItem(at: url) + guard let service = services[fpUiExtensionServiceName] else { + throw FileProviderCommunicationError.serviceNotFound + } + let connection: NSXPCConnection + connection = try await service.fileProviderConnection() + connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self) + connection.interruptionHandler = interruptionHandler + connection.resume() + guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else { + throw FileProviderCommunicationError.remoteProxyObjectInvalid + } + return proxy +} diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Sharing/ShareTableViewDataSource.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Sharing/ShareTableViewDataSource.swift index 3cca1d1a9..f0d0baf99 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Sharing/ShareTableViewDataSource.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Sharing/ShareTableViewDataSource.swift @@ -84,7 +84,9 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele } do { - let connection = try await serviceConnection(url: itemURL) + let connection = try await serviceConnection(url: itemURL, interruptionHandler: { + Logger.sharesDataSource.error("Service connection interrupted") + }) guard let serverPath = await connection.itemServerPath(identifier: itemIdentifier), let credentials = await connection.credentials() as? Dictionary, let convertedAccount = Account(dictionary: credentials), @@ -118,25 +120,6 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele } } - private func serviceConnection(url: URL) async throws -> FPUIExtensionService { - let services = try await FileManager().fileProviderServicesForItem(at: url) - guard let service = services[fpUiExtensionServiceName] else { - Logger.sharesDataSource.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.sharesDataSource.error("Service connection interrupted") - } - connection.resume() - guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else { - throw NSFileProviderError(.serverUnreachable) - } - return proxy - } - private func fetch( itemIdentifier: NSFileProviderItemIdentifier, itemRelativePath: String ) async -> [NKShare] { diff --git a/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj b/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj index 0a6e23366..ff6aa0624 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj +++ b/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 537630982B8612F00026BFAB /* FPUIExtensionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537630962B860D920026BFAB /* FPUIExtensionService.swift */; }; 537BD67A2C58D67800446ED0 /* LockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537BD6792C58D67800446ED0 /* LockViewController.swift */; }; 537BD67C2C58D7B700446ED0 /* LockViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 537BD67B2C58D7B700446ED0 /* LockViewController.xib */; }; + 537BD6802C58F01B00446ED0 /* FileProviderCommunication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */; }; 538E396A27F4765000FA63D5 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */; }; 538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */; }; 538E397627F4765000FA63D5 /* FileProviderExt.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 538E396727F4765000FA63D5 /* FileProviderExt.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -167,6 +168,7 @@ 537630962B860D920026BFAB /* FPUIExtensionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FPUIExtensionService.swift; sourceTree = ""; }; 537BD6792C58D67800446ED0 /* LockViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockViewController.swift; sourceTree = ""; }; 537BD67B2C58D7B700446ED0 /* LockViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LockViewController.xib; sourceTree = ""; }; + 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderCommunication.swift; sourceTree = ""; }; 538E396727F4765000FA63D5 /* FileProviderExt.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileProviderExt.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; }; 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderExtension.swift; sourceTree = ""; }; @@ -353,6 +355,7 @@ 537BD6782C58D0FC00446ED0 /* Locking */, 537BD6772C58D0C400446ED0 /* Sharing */, 53B979802B84C81F002DA742 /* DocumentActionViewController.swift */, + 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */, 53FE14572B8E3A7C006C4193 /* FileProviderUIExt.entitlements */, 53B979852B84C81F002DA742 /* Info.plist */, ); @@ -725,6 +728,7 @@ 53FE14592B8E3F6C006C4193 /* ShareTableItemView.swift in Sources */, 5376307D2B85E2ED0026BFAB /* Logger+Extensions.swift in Sources */, 53FE14502B8E0658006C4193 /* ShareTableViewDataSource.swift in Sources */, + 537BD6802C58F01B00446ED0 /* FileProviderCommunication.swift in Sources */, 537630982B8612F00026BFAB /* FPUIExtensionService.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;